Skip to content

fix bug #53432 (Assignment via string index access on an empty string converts to array) - #463

Closed
bixuehujin wants to merge 1 commit into
php:masterfrom
bixuehujin:bug53432
Closed

bixuehujin wants to merge 1 commit into
php:masterfrom
bixuehujin:bug53432

Conversation

@bixuehujin

Copy link
Copy Markdown
Contributor

see https://bugs.php.net/bug.php?id=53432

  • Assignment via string index on an empty string will produce a Illegal string offset
    warning now.
  • Split Zend/tests/indexing_001.phpt into multiple files for readability improvement.

… converts to array)

see https://bugs.php.net/bug.php?id=53432

- Assignment via string index on an empty string will produce a Illegal string offset
warning now.

- Split Zend/tests/indexing_001.phpt into multiple files for readability improvement.
@smalyshev

Copy link
Copy Markdown
Contributor

This is a serious change in how conversions work, so I don't think it can be done in 5.x

@yohgaki

yohgaki commented Nov 20, 2013

Copy link
Copy Markdown
Contributor

May be PHP 6?
We are discussing this issue on internals@php.net. If you would like to discuss, please subscribe the list.

@bixuehujin bixuehujin closed this Aug 23, 2014
heyJordanParker added a commit to heyJordanParker/php-sharp that referenced this pull request Oct 13, 2026
Problem: a property written `required` was "not supported yet", and a
struct created without one of its properties compiled: `new Point { x:
1 }` left `y` unset until the engine threw on the first read. Jordan's
Q2 rules that a struct's property without an initial value is set at
creation, a `T?` one too. Task php#463: a get-only property that no
constructor sets compiled.

Solution: `MetadataFlags::REQUIRED` marks a property written `required`,
and a struct's property without an initial value that is not a main
constructor parameter. Neither takes a `null` default. The codex scanner
records on each constructor, main or named, the properties it assigns on
every path, as `MethodMetadata::assigned_properties`: both arms of an
`if`/`else`, every `match` arm, and a path that throws counts as done. A
call to a helper method counts for nothing, as in C# and Swift. At each
`new`, the required properties that the constructor running (a named
constructor together with the main constructor) does not assign must be
named by the object initializer: "`new Point` must set `y` and `label`."
A `required` property without `init` or `set` is refused where it is
written. A get-only property with no initial value that no constructor
assigns is an error: "`count` is get-only and never set: set it in the
main constructor, or give it an initial value."

crates/
├── syntax/
│   ├── src/parser/internal/class_like/method.rs  <- `required` goes on a property
│   ├── src/cst/cst/with.rs                       <- doc paragraphs clippy asks for
│   └── tests/sharp.rs                            <- `required` rows name a method
├── codex/src/
│   ├── metadata/flags.rs                         <- MetadataFlags::REQUIRED
│   ├── metadata/function_like.rs                 <- MethodMetadata::assigned_properties
│   ├── scanner/property.rs                       <- `required` sets REQUIRED, no null default
│   ├── scanner/class_like.rs                     <- require_struct_properties
│   ├── scanner/function_like.rs                  <- definitely_assigned_properties
│   └── scanner/mod.rs                            <- a named constructor's assigned set
├── semantics/
│   ├── src/internal/checker/sharp.rs             <- `required` needs `init` or `set`
│   └── tests/sharp.rs                            <- a_required_property_has_init_or_set
├── analyzer/
│   ├── src/expression/instantiation.rs           <- check_required_properties at `new`
│   ├── src/statement/class_like/initialization.rs <- check_get_only_initialization
│   ├── src/statement/class_like/mod.rs           <- runs it
│   └── tests/sharp.rs                            <- every_required_property_is_set_where_its_object_is_created,
│                                                    a_get_only_property_no_constructor_sets_is_an_error
└── sharp-bridge/tests/lower.rs                   <- fixtures set their get-only properties;
                                                     parse reports a missing `owner`
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.

3 participants