Skip to content

Add default value for length in mb_substr and mb_strcut - #133

Closed
Irker wants to merge 1 commit into
php:masterfrom
Irker:null_default_in_mbstring
Closed

Irker wants to merge 1 commit into
php:masterfrom
Irker:null_default_in_mbstring

Conversation

@Irker

@Irker Irker commented Jul 17, 2012

Copy link
Copy Markdown
Contributor

In this commit(s) I added "null" default values for length in mb_strcut and mb_substr.
So now we can write:
$result = mb_substr("12345", 2, null, "UTF-8");
And get expected result : "345"

I added this similar to function array_slice (length parametr) php.net/manual/en/function.array-slice.php

I think no great BC there. All exist tests passed.

If you like this idea, I can add tests for my patch.

Yes, I know about mb_internal_encoding.
Yes, I know about discussion about "default" keyword.

@hirokawa

Copy link
Copy Markdown
Contributor

I think that this patch is valuable, and acceptable.

@lstrojny

Copy link
Copy Markdown
Contributor

@Irker this fixes a long standing inconvenience, thanks. Could you add a test case?

@php-pulls

Copy link
Copy Markdown

Comment on behalf of lstrojny at php.net:

Merged to PHP-5.4 and master. Thanks for your contribution!

@php-pulls php-pulls closed this Sep 2, 2012
danielbachhuber added a commit to wp-cli/php-cli-tools that referenced this pull request Aug 4, 2014
heyJordanParker added a commit to heyJordanParker/php-sharp that referenced this pull request Oct 13, 2026
Problem: tests/sharp_messages.rs read test sources to demand a .php twin
beside each .sharp message test. Most twins it forced asserted that a .php
file reports nothing for a rule the PHP# gate already keeps out of .php
files, so they proved no spec rule and failed on no real bug. Others pinned
upstream text the .sharp rule never touches. Fifteen twins pinned an upstream
Mago miss as correct: PHP refuses the file and Mago reports nothing. Four
.sharp messages still pointed at fixes PHP# does not have: "or not imported",
a help without the PHP# call forms, a type message named after PHP's kinds,
and `as` for an `Any?`, which leaves it nullable.

Solution: tests/sharp_messages.rs and the root package's proc-macro2, syn and
regex dev-dependencies are deleted. A .php twin stays only where the .sharp
rule changes code .php also runs, such as a display function with a dialect
branch or a check that splits on `is_sharp()`, and it asserts only that
shared path's messages, filtered as `stepping_or_ordering_an_any_names_it_any`
filters. Each upstream miss is an after-v1 issue, #133 to #147, that names the
PHP error, the code and the test. The four .sharp messages are reworded, and
the comparison and spaceship helps move with the `Any?` help. Each .php
message stays byte for byte. The sharp-bridge tests run the same banned-word
check on every issue they check.

Cargo.toml                          <- root dev-dependencies proc-macro2, syn, regex deleted
Cargo.lock                          <- their edges deleted; regex edge added to mago-sharp-bridge
tests/sharp_messages.rs             <- deleted
crates/analyzer/
├── src/expression/
│   ├── binary/arithmetic.rs        <- `Any?` operand help: check with `is` or `match`
│   ├── binary/comparison.rs        <- `Any?` comparison help: check with `is` or `match`
│   ├── binary/spaceship.rs         <- `Any?` `<=>` help: check with `is` or `match`
│   ├── unary.rs                    <- `Any?` negate, increment, decrement help: `is` or `match`
│   ├── call/mod.rs                 <- missing function help: spelling, `this.f()`, `Class.f()`, a `.php` file
│   └── constant_access.rs          <- missing constant: no "or not imported"; help names PHP# constants
├── src/statement/function_like/mod.rs  <- "Cannot find type `Missing`."
└── tests/sharp.rs                  <- [] twins deleted; kept twins filtered to the shared message
crates/semantics/tests/sharp.rs     <- [] twins deleted; kept twins filtered to the shared message
crates/sharp-bridge/
├── Cargo.toml                      <- regex dev-dependency
└── tests/common/mod.rs             <- checked_file fails on a .sharp issue that names a PHP-only word
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants