Skip to content

Run section 6's fields and properties on the engine - #132

Merged
heyJordanParker merged 43 commits into
masterfrom
feat/properties
Oct 15, 2026
Merged

heyJordanParker merged 43 commits into
masterfrom
feat/properties

Conversation

@heyJordanParker

@heyJordanParker heyJordanParker commented Oct 15, 2026 •

Copy link
Copy Markdown
Owner

Completes: §6, §6.1, §6.2, §6.3, §6.4, §6.5

Problem

Section 6, fields and properties, had nine spec examples in sharp/baseline/spec. PHP# refused observers, via, lazy, static accessor bodies, non-constant static initial values and plain PHP property overrides as "not supported yet". It silently accepted a property that no path through the constructor sets, which threw on its first read.

Solution

Every section 6 rule now compiles, refuses or runs as the spec annotates, in the checker, the bridge and the engine. Each Capability has an engine test that runs in all four opcache modes.

  • Fields, properties and initial values. No code that can read the object runs before the object is built. An initial value can't read this, and it fills the storage without running a set body, constant or not: a constant one is PHP's default, and any other runs at the start of the constructor, through PHP's ReflectionProperty::setRawValue when the property has a set hook. Only a behavior's set processes it. A static's non-constant initial value runs once each request, when the request first uses the class's statics, in the hidden #statics method the engine calls from zend_class_init_sharp_statics. Engine: fields.phpt, initial_values.phpt, overrides.phpt, preloaded.phpt.
  • No implicit starting value. A member, T? included, has no implicit null and no default filler. A field or a property with storage and no initial value must be set on every path through the main constructor, or the error names both fixes. A static with storage needs an initial value whatever its type.
  • Access levels. Only set and init take an access level of their own, and one on get is an error. internal set reaches the property's namespace and every namespace below it.
  • Getters. A get body may have any effect but never writes this, which is less than readonly promises.
  • Overrides (6.1). A PHP# property overrides a plain PHP parent's property. A PHP# property is closed unless it is virtual or abstract, and a plain PHP child may still override it. An interface may state { get; set; }. Engine: overrides.phpt.
  • Observers (6.2). willSet and didSet run inside the set hook, only once the object is built: never on an initial value, a write while a constructor, a named constructor or an object initializer runs, or the values a with copy is written with. set and init bodies still run for those writes. field in willSet reads the value the write replaces. The engine's new Sharp\Internal\building($object) tells whether an object is still being built: a frame up the stack runs one of its constructors, or the object carries the new object flag IS_OBJ_SHARP_BUILDING. The new Sharp\Internal\build($object, $body, ...$arguments) sets that mark while it runs a named constructor's body or an object initializer on the object, as Closure::call does, and puts back the mark it found whether the body returns or throws. clone() sets it while it writes a with copy's values. Engine: observers.phpt.
  • Property references (6.3). nameof(X.y) is the compile-checked string of a property's name. Engine: name_of.phpt.
  • Behaviors (6.4). via Trimmed, Logged<string> runs a property through classes that implement the new Sharp\Behavior<T>. Each object holds one hidden slot per behavior, and the constructor fills them before any initial value. A copy, made with with or plain PHP's clone, gets its own through a hidden __clone. set runs the behaviors in written order and get runs them the other way, and a read or write carries their effects. Engine: behaviors.phpt.
  • lazy (6.5). An instance lazy property computes on its first read and keeps the value, and a copy computes it again. A static lazy keeps it for a singleton's lifetime, through the new Sharp\Internal\keep. Engine: lazy.phpt.
  • Static properties. A static property runs a computed body, accessor bodies and observers through the hidden static methods name#get and name#set, since PHP has no hooks on a static property.
  • Section 5's internal. It reaches its namespace and every namespace below it. A project warns on a public member that nothing outside its namespace uses. Engine: reach.phpt.
  • Reflection. ReflectionProperty::isField() tells a PHP# field from a property.

Generic implementations

Trimmed : Behavior<string> with string set(string value) was refused by the erased signature check of #102. PHP would refuse the class when it links, because Behavior.set erases its parameter to mixed. A PHP# class's own method whose parameter takes the type argument of a type parameter its parent names is now widened, as Java's bridge method takes the erased type. The bridge marks the parameter ZEND_PARAM_WIDENED, so it keeps its PHP type and the engine skips it in the inheritance check. A call from plain PHP gets the engine's own TypeError: Handlers\OrderHandler::handle(): Argument #1 ($item) must be of type Handlers\Order, string given. Engine: handlers.phpt, through an interface and through a class override.

The refusal stays where widening can't help:

  • a plain PHP class narrowing a PHP# generic method, because the bridge lowers only PHP#
  • a method the class inherits from another class
  • a narrowing that no type parameter explains, such as PHP's parent or callable, which would refuse calls the parent accepts

Still refused as "not supported yet"

  • accessor bodies and non-constant initial values on a static of a generic class, because each type argument's statics start as a copy of constant values

Verification

  • sharp/bin/test --opcache --repeat Zend/tests/sharp: 278 of 278 pass in each of the four modes.
  • sharp/bin/test --passes over every PHP# test, in four groups: all 19 runs of each group pass.
  • sharp/bin/test --census --differential --spec: the census and differential pass, and 17 of 17 self-test examples pass.
  • sharp/bin/test Zend/tests: 5562 pass, 0 fail. sharp/bin/test ext/reflection ext/opcache: 1441 pass, 0 fail.
  • sharp/bin/spec: "Checked 197 examples, ignored 1, and 34 fail", equal to sharp/baseline/spec.
  • sharp/bin/spec --base origin/master: "0 entries join sharp/baseline/spec, 9 leave it."
  • sharp/bin/spec --completes on this body: every section passes, from "§6: all 13 checked examples pass" to "§6.5: all 1 checked examples pass".
  • mago: the analyzer, semantics, syntax, codex and sharp-bridge suites, the sharp (71) and compile (78) integration tests, and clippy -D warnings on each changed crate. diff-cover of the analyzer, semantics and bridge: every changed line runs except 12 that are unreachable! alone.
  • mago analyze of the standard library reports nothing at the note level.

The design note states every rule of spec section 6 and 6.1 to 6.5, its state on master e19d4c2, and the mechanism that will serve it, with 13 questions for Jordan and 6 decisions for team-lead.
…for overrides

Queue 1 asked for every line of section 5 about internal, the section 12 reading of new List<Tag>(), and which redeclared property forms PHP runs.
…akes no accessor body

Problem
- Section 6 line 237: `private static int misses;` compiled, and its first read threw at runtime.
- Section 9 line 447: an accessor body on a constructor parameter compiled, against the rule that such a
  member takes access levels and attributes only.
- A class whose property has the class's own name, as `class Coupon { public string coupon { get; } }`
  with a constructor, was refused as a method and a property sharing a name.
- Section 6 line 207 wrote `new List<Tag>()`, which section 12 never makes: a collection is a literal.

Solution
- Semantics reports a static field or property with storage, no initial value and a type that isn't
  `T?`, and names both fixes: "Give `misses` an initial value, or make it `int?`".
- Semantics reports each accessor body on a constructor parameter with section 9's fix. A parameter's
  member then always has storage, so its no-storage check and the bridge's parameter hooks go.
- The name-clash check skips the constructor, which PHP names `__construct`.
- Line 207 writes `= [];`, and the harness declares `extern Str;`, so line 198's getter is pure.
- `Accessors.sharp` and its twin set `city` from the constructor through a class-body property.

sharp/
├── mago/crates/semantics/src/internal/checker/sharp.rs   static rule, parameter bodies, constructor name
├── mago/crates/sharp-bridge/src/lower.rs                  member_flags: a parameter has no hooks
├── harness/app/Stubs/Str.sharp                            new: extern Str;
└── baseline/spec/§6/                                      initial-values and static-initial-values leave
docs/spec.md                                               line 207 writes = []
Zend/tests/sharp/Accessors.{sharp,inc}, accessor_bodies.phpt
…ess virtual or abstract

Spec section 6.1 overrides a plain PHP parent's property with a property marked
`override`, and a PHP# property opens like a method (section 22).

- A property needs a type: `protected override table { get; set; }` is the
  named parse error `UntypedPropertyInSharp`.
- `override`, `virtual` and `abstract` go on properties only. A field with any
  of them names the property to write. An abstract property has no body and no
  initial value.
- The codex marks a closed PHP# property final, and the analyzer says
  "Cannot override `Base.closed`: a PHP# property is closed unless it is
  `virtual` or `abstract`." A `protected` field stays open.
- Over a plain PHP parent, every accessor form PHP runs compiles. A get-only
  or `init` override, and a `set` at another level than the parent's, are
  errors that name the parent and why.
- A missing `override` is reported on every property. A field that replaces a
  parent's property names the property form.
- The untyped-parent and PHP#-parent "not supported yet" refusals go.
- An abstract property lowers as an interface property does.
- Decision 028, the spec's override example and the engine fixtures move to
  the property form. `plain-php-property-override` passes, and its baseline
  entry goes.
3cb4d99 added `ParseError::UntypedPropertyInSharp`, and `mago-hir`'s
exhaustive match did not compile without it.
Spec section 6.3, after C#'s `nameof`.

- `NameOf` is a CST node beside `TypeOf`, and `nameof` joins the PHP#
  keywords, so it can't name a local. In PHP it stays a function call.
- The class resolves as `typeof`'s does. The property is a member's name,
  never a local.
- The analyzer types it as the literal string of the name. A property or
  field the class lacks is "Property `Order.totl` does not exist.", and one
  not readable at the call is "`Order.secret` is `private`, so `nameof`
  can't name it here."
- The bridge lowers it to the string, `sharp-lean` translates it as that
  string, and the inliner reads it as pure.
- `NodeKind.php` is regenerated. `property-references` passes, and its
  baseline entry goes.
…the value

Spec section 6.5. `lazy T name => expr;` is the only form.

- Semantics lets `lazy` onto a computed property. With accessors or on a
  field it names the form, and on a method it says only a property is lazy.
- The bridge gives it a `get` hook that keeps the value in the property's
  storage, `get => $this->name ??= expr;`, behind `private(set)`. A
  nullable one can keep null, so a hidden `name#lazy` flag beside it says
  whether the body ran. A throw keeps nothing, so the next read runs again.
- The body is a getter, held to getter purity until Jordan rules on it.
- `lazy-property` passes, and its baseline entry goes. `static lazy` stays
  refused as a static computed property.
Spec section 5, whole, except the too-wide warning, whose package scope
waits for Jordan.

- Semantics admits `internal` on classes, interfaces, enums, events,
  constants, properties, methods and parameters, and on `set` and `init`
  when narrower than the property. A field, or a constructor parameter
  without accessors, can't be `internal`.
- `internal(App.Tenant)` is a named parse error: "`internal` takes no
  namespace: move the shared helper to the parent namespace."
- A file declares the namespace its PSR-4 folder holds, from the nearest
  composer.json, and a file in an `autoload-dev` folder may declare any
  namespace. The database keeps it as `File::folder_namespace`.
- A PHP# class-like without `public` is `internal`. A member reaches no
  further than its class.
- The analyzer refuses code outside the reach where it reaches: the
  import, a method call, a property read or write (`internal set` names
  `Shop.views.set`), and a constant. "`Hidden` is internal to
  `App.Tenant.Store`, and `App.Tenant.Other` is outside it." Plain PHP
  is never checked.
- The bridge runs `internal` as public, `internal set` with no set level,
  and `internal init` as protected(set), as every `init`. A property with
  no access modifier is private by its flags, so `internal` counts.
- Every engine fixture, spec example, harness and library file runs
  through the default. It refuses one: the bridge test's `Lib.Stamped`,
  which another namespace extends, is now `public`.
- `field-and-property` passes, and its baseline entry goes.
Spec section 6.1's "Reflection that tells fields from properties".

- `ZEND_ACC_FIELD`, property flag bit 13, marks a field. The bridge sets
  it on every field, and on a promoted constructor parameter without
  accessors. The compiler keeps it when it promotes a parameter.
- `ReflectionProperty::isField()` reads it, beside `isVirtual()`.
  `getProperties()` keeps listing both, as plain PHP tools expect, and
  `getModifiers()` leaves the bit out.
- A plain PHP property, a PHP# property, and a property that overrides
  a protected field are not fields.
Spec section 6.1's interface properties, which section 22's
`interface-defaults` example writes as `List<string> claims { get; set; }`.

- Semantics takes `{ get; }` or `{ get; set; }` on an interface property,
  both accessors bare. A body, or a `set` with an access modifier, stays
  "not supported yet".
- A class gives it `{ get; set; }`. One that gives it get-only is refused:
  "`Fixed` gives `total` get-only, and `Settable` states it with `set`.",
  by the analyzer's existing check of an interface stated with `set`.
- The bridge lowers it to PHP's interface property with `get` and `set`,
  and a write through the interface reaches the class's property.
…terface member error

Spec section 5: an interface member is always public, so it takes no
access modifier. `{ get; private set; }` or `{ protected get; set; }` in
an interface now gets "An interface member is always public, so it takes
no access modifier.", as a modifier on an interface method or property
does, in place of "not supported yet". `check_accessors` skips an
interface property, whose accessors `is_interface_property` took.
An access modifier on an interface property's `set`, as in
`{ get; private set; }`, keeps the interface member error, and its help
now says what to write: "Declare `{ get; }` in the interface, and
`{ get; private set; }` in the class." A modifier on `get` says to remove
it.

`Account` in `Overrides.sharp` gives the interface's get-only `name` with
`{ get; private set; }`: it compiles, its own method writes it, and a
write from outside fails as PHP's private(set).
…a project

Spec section 5's too-wide warning, with Jordan's package scope.

- `too_wide_members(codebase, references)` in `unused_members.rs`, which
  the analyzer's root re-exports, warns on a `public` member of a public
  PHP# class that nothing outside its namespace and the namespaces below
  it uses: "`Cart.count` is public, and nothing outside `App.Shop` uses
  it." (`too-wide-member`, a warning). A use from inside the namespace,
  the member's own class included, is no outside use, and a member
  nothing uses warns too. Properties, methods, constructors (named as in
  `Cart.Cart`) and constants count.
- Exempt: interface members, a member that overrides or implements
  another, PHP's magic methods other than the constructor, the members of
  an `internal` class, and plain PHP.
- It reads every file's uses, so it runs once after `Effects::solve` in
  `IncrementalAnalysisService::run_analyzer_selective` and
  `AnalysisService::oneshot`. The incremental path merges the external
  and late references before both passes, and their issues share one
  per-file slot, renamed `project_issues`, and the pragma reconciler.
- It runs only in a project: the loader sets `File::is_project` from the
  nearest composer.json's `"type": "project"`, and the codex marks the
  file's PHP# class-likes `MetadataFlags::PROJECT`. A library, Composer's
  default type, gets none, because its uses are in the projects that
  install it. The spec says so in section 5.
Jordan's rulings on getters and `lazy`:

- "Getters must be pure." is gone. A `get` body, a `lazy` body included,
  has whatever effects its body has, and a read of the property carries
  them, so a law reading it is held to them.
- A `get` body never writes `this`, checked as a method marked
  `readonly`: writing a field of `this`, or calling a method that writes
  one, is the error "Getter `next` changes `this.count`. A getter never
  writes `this`." (`getter-writes-this`, which replaces
  `impure-getter`). The value a `lazy` property keeps is the language's
  write, not the body's.
- `Effects::bodies_with` gives each body a check finds a reason for, and
  `getters_never_write_this` asks for a change of `this` alone.
- `Sharp\Environment`'s `variable` and `require` are `@mutation-free`
  in the prelude stub, as they only read. Without it a getter reading the
  environment was refused as a change of `this.environment`.

The spec states the rule in section 6.1 with the `getter-writes`
example, rewrites section 6.5's "may read anything", and drops the line
from section 29. The tests that used a getter as the pure place now read
it from a law, and new rows cover a getter and a `lazy` body with an
effect compiling, a law reading them refused, and a `lazy` body with an
effect running once in every opcache mode.
Both sides kept, with these resolutions:

- `ZEND_ACC_FIELD` moves to bit 15, because master's
  `ZEND_ACC_SHARP_HIDDEN` and `ZEND_ACC_SHARP_TYPED` take 13 and 14. The
  bridge's copy and the bridge tests' flag values follow (32772, 32770,
  32786, 32788).
- `MetadataFlags::FOREIGN` keeps bit 51, and `INTERNAL_SET` and
  `PROJECT` move to 52 and 53.
- A promoted parameter keeps master's `is_promoted_property()` gate and
  `property_hint`, and lowers no hooks: section 9 refuses an accessor
  body on a parameter, so master's bridge test of one goes.
- `Environment` is now the standard library's `foreign` class, so the
  prelude stub this branch marked `@mutation-free` goes.
- Master's tests that used a getter as the pure place now read it from a
  law, as this branch's do, and name plain PHP functions `global.`.
- Master's generic statics test drops `static int total { get; set; }`,
  which section 6 refuses without an initial value.
, #128, #129, #130)

Both sides kept, with these resolutions:

- `MetadataFlags::STRUCT`, `REQUIRED` and `OPERATOR` keep bits 52 to
  54, and `INTERNAL_SET` and `PROJECT` move to 55 and 56.
- `required` keeps master's check beside this branch's field and
  abstract property rules, and master's "Overriding a property is not
  supported yet" goes, as this branch builds overrides.
- A promoted parameter takes master's `promoted_beside` gate and still
  lowers no hooks, since section 9 refuses an accessor body on one;
  master's bridge test of one goes again.
- An interface property's hooks come from `abstract_hooks`, fitted to
  master's `hook` with its parameters.
- A property keeps the default private judged by its flags, with
  master's crossing attribute.
- The too-wide pass skips a method the codex gives a class, such as
  section 10's `parse`, which spans the whole class.
- Master's event tests that used a getter as the pure place read it from
  a law.
- `code.rs` is regenerated from the merged code list.
…s less than readonly

Jordan's ruling is "a `get` body may have any effect but never writes
`this`". Section 6.1 now states it in his words, and says how a getter
differs from a method marked `readonly`: it may call a plain PHP method,
and a PHP# method not marked `readonly` that writes nothing of `this`.

The getter rule's docs and note no longer call a getter a `readonly`
method, and the getter row adds the spec's accessor over Eloquent's
`getAttribute`, which compiles with no effect issue. The `lazy` row's
`this.rows.find(1)` body already compiles.
Jordan's ruling on question 7. `get` reads at the property's own level,
so `{ protected get; set; }` is no longer "This accessor is not supported
yet" but the error "Only `set` and `init` take an access level: `get`
reads `views` at the property's own level.", with the help "Write
`get;`, and to read `views` only inside the class, write a method that
reads it there, such as a `private` method that returns `this.views`."

The spec's lines that gave each accessor its own level (sections 6, 6.1
and 9) now give one to `set` and `init` only, and section 6.1 states the
rule with the `access-on-get` example.
…T? included

Jordan's ruling on question 13. A settable property with storage that
isn't `T?`, `init` or `required` and has no initial value is an error
unless every path through a constructor sets it: "`views` is never set:
set it in the main constructor, or give it an initial value.", with the
note "A property that isn't `T?` holds a value from the start, and no
constructor sets it on every path." It is #123's check, which now takes
the class's members to tell a settable property from a field.

A get-only `T?` without an initial value is no longer "not supported
yet": the same check holds it to every path, and the bridge lowers it
to PHP's `readonly` with no default. `nullable-members` passes, and its
baseline entry goes.

The spec states both in section 6.1, adds `level` and `rank` to the
`nullable-members` example, and gives each settable property in its
examples an initial value. `Overrides.sharp` gains `Member`, run in
every opcache mode. Bridge and analyzer tests whose sources left a
settable property unset now set it, and master's struct test expects
the field flag on its static field.
Jordan's ruling on question 8: observers run on every write, the
initial value's and the constructor's included, and also when the
value is unchanged.

- Semantics takes `willSet` and `didSet` with a body, beside `set`.
  Without `set` it is "`didSet` needs a `set` accessor". `willSet`
  cannot change or stop the write, so writing `value` or returning in
  it is an error, and so is returning in a `set` body before `didSet`.
  On a constructor parameter it is section 9's "Declare `title` in the
  class body to give it `didSet`".
- `field` in `willSet` is "not supported yet" until Jordan rules what it
  holds before the first write (Queue 12).
- An observer binds `value`, and its body is analyzed in the `set`
  hook's context. It keeps its own effect summary, which every write
  calls beside `set`, so a law building the object reaches it.
- The bridge writes one `set` hook: `willSet`, the `set` body or the
  storage write, then `didSet`. An observed property's initial value is
  a write at the start of the constructor, so the observers see it.
- Section 6.2 states the rule, and `change-observers` passes and
  leaves the baseline. `Observers.sharp` and `observers.phpt` run each
  write site in every opcache mode.
…ts class loads

Decision 3 and question 12. A get-only static is no longer "not
supported yet": PHP has no `readonly` static, so it is `private(set)`,
and the analyzer refuses every write of it, its own class's included,
with the get-only error a computed property's write gets.

A static's initial value that isn't constant is no longer "not
supported yet" either. It runs once, right after the class is declared,
in `\Closure::bind(static function () { self::$a = ...; }, null,
Report::class)()`, which writes a `private(set)` static too. A generic
class's statics start as a copy of constant values per type argument,
so there it stays "not supported yet".

`Property::initial_value_runs_in_constructor` now leaves statics out,
and `Property::initial_value_runs_after_class` names theirs. Section 6
states both rules with example lines, and `Overrides.sharp` gains
`Registry`, run in every opcache mode.
…ervers

Decision 3. PHP has no hooks on a static, so a static computed property
or one with an accessor body or an observer runs its accessors as its
class's hidden static methods: `name#get` at the property's level, and
`name#set` at its `set`'s, which runs the observers around the `set`
body or the storage write. Its storage, when it has one, is a static
under `private(set)` that only they write, and `field` is `self::$name`.

Every PHP# read of `Class.name` calls `Class::{'name#get'}()`, and every
write calls `name#set` with the value held in a hidden variable, so the
write's value is the value written: `Class::{'name#set'}($value#1 = v)
?? $value#1`. A compound assignment reads through `name#get`, a postfix
`++` gives the value read, and an element write goes through
`element_write`, as on an instance property with hooks. An observed
static's initial value calls `name#set`, so its observers see it.

The analyzer gives a static property's accessors no `this`, as a static
method has none, reads `field` as the static storage, and reaches the
accessors' effects from `Class.name`. The codex marks a static computed
property static. A generic class's statics are entries of one table
with no accessors, so there they are "not supported yet".

`Overrides.sharp` gains `Tally`, run in every opcache mode.
Queue 4, Proposal A. A `static lazy` property's hidden `name#get`
returns `\Sharp\Internal\keep('App\Report::name', static fn () =>
body)`. The new engine function keeps the value under that key in the
container's singleton store, so it lives as long as a singleton service,
and `sharp_container_forget` clears it when a test starts or ends. A
throw in the body keeps nothing, so the next read runs it again.

`keep` is in `sharp.c` and `sharp.stub.php`, with `sharp_arginfo.h`
regenerated. `Lazy.sharp` gains `Loads.first` and `Loads.ratio`, run in
every opcache mode.
…tion takes its type argument's type

Spec section 6.4: `public string name { get; set; } via Trimmed, Tracked = "";`
names behaviors, classes that implement the new `Sharp\Behavior<T>` for the
property's type. The bridge gives each one a hidden private slot,
`name#via0`, which the constructor fills with `new` before any initial
value. `set` runs the behaviors in written order and `get` runs them the
other way. The analyzer refuses a behavior for another type, a class that
is no behavior, and one that `new` with no arguments can't create, as
`invalid-property-behavior`. Semantics keeps `via` to an instance
auto-property with `get; set;`, and a constructor parameter refuses it.

Queue 13: `Trimmed : Behavior<string>` with `string set(string value)` was
refused by #102's erased signature check. A PHP# class's own method whose
parameter takes the type argument of the type parameter its parent names
is now widened, as Java's bridge method takes the erased type. The analyzer
records it in `AnalysisArtifacts::widened_parameters`. The bridge declares
it with no PHP type and lists its written type in the method's metadata,
so a call from plain PHP gets the engine's TypeError. The refusal stays for
a plain PHP class, a method the class inherits, and a narrowing that no
type parameter explains, such as `parent` or PHP's `callable`.

Engine: behaviors.phpt and handlers.phpt, in every opcache mode.
The folder namespace rule gave a file under `app/it's\here/` the namespace
`App.it's\here` and asked it to declare `namespace App.it's\here;`, which
no file can parse. The rule now names the folder to rename instead.

Master's compile_quotes_each_input_path_of_the_listener_table put its file
in that folder, so it failed on this branch since the merge. It now keeps
the `'` and `\` in the PSR-4 folder that maps `App`, which any directory
name may be, and still proves the listener table quotes both.
…n 6 built

The semantics contract still called static accessor bodies, static computed
properties and a get-only T? without an initial value "not supported yet",
listed interfaces as get-only, and named neither observers, via nor lazy.

The spec self-test's `refusal` example relied on a static accessor body
being "not supported yet", which this branch built, so it now uses a method
without an access level, which stays refused.
… every line the branch adds

A static property with a `get` body and no storage, such as
`public static int squared { get { return 2 * 2; } }`, was refused with
"Give `squared` an initial value": the rule's own doc said it covers a
property with storage, and the check never asked. Engine: overrides.phpt
reads `Tally.squared`.

CI's patch coverage counts the analyzer, semantics and bridge tests only, and
109 changed lines ran only under mago's integration tests or no test. New rows:
the too-wide warning over a project of six files, every static accessor form
and write in the bridge, an untyped `via` property, `nameof` on a class whose
parent is missing, an interface property with three accessors, and `didSet`
returning a value. Two branches no program reaches are written so they have no
line of their own.

The typos check refused `Ordr`, a deliberately missing class in the nameof
test, which is now `Missing`.
… as too wide, and INTERNAL is PHPDoc's again

Review finding 3: a settable or get-only property a concrete class inherits
from an abstract PHP# parent went unchecked, so `Child : Base` read an unset
`count` and threw. `check_get_only_initialization` now walks every property
the class declares or inherits from PHP#, counts what each parent's
constructor assigns through `: super(…)`, and reports an inherited one on the
class: "`Child` never sets `count`, which it inherits from `Base`". It reads
settable from the metadata, so it no longer takes the class's members, and the
new `MetadataFlags::FIELD` tells a field from a property, as the engine's
`ZEND_ACC_FIELD` does. Every message now ends "give `count` an initial value,
or set it on every path through the constructor", as the spec writes it.

Review finding 10: the too-wide warning skips a constructor, which `new` calls
at its class's reach. The spec says so.

PHP#'s `internal` reach is now `MetadataFlags::INTERNAL_REACH`, so
`MetadataFlags::INTERNAL` keeps only PHPDoc's `@internal`.
…essors keeps private storage

Review finding 8: `via Hidden` compiled though `Hidden`'s constructor is
private, so the owning class's constructor failed on `new \App\Hidden()`.
`check_behavior` now refuses a constructor the owning class can't call,
`private` or `protected` outside its class, or `internal` outside its
namespace: "`Order` can't create `Hidden`: its constructor is `private`".

Review finding 6: the storage of a static with an accessor body, a computed
body or an observer was public under `private(set)`, so plain PHP read a raw
value its accessors never saw. It is now private, plain PHP gets PHP's access
error (overrides.phpt), and section 6 says plain PHP reaches such a static
only through a method.
Review finding 9, as Queue 15 corrected it: PHP# checks only `.sharp` code,
and plain PHP test doubles must keep working, so `override-final-property`
and `override-final-method` skip a plain PHP subclass of a PHP# class. A PHP#
subclass keeps both reports, and PHP's own refusal of a property whose `set`
is private, which it makes final, stays. Engine: overrides.phpt's
`LegacyFigure` overrides `Figure`'s closed `title` and `name()`.
Review finding 1: `with` and plain PHP's `clone` copied the behavior slots,
so a copy and its original shared each behavior's state. A class with
behaviors or instance `lazy` properties now gets a hidden `__clone`, which
runs the parent's first when it has one, creates each behavior again, and
clears each `lazy` flag.

Queue 14's smaller item: a copy made with `with`, on a struct or an object,
kept the original's `lazy` values. It now computes them again on its first
read, as Kotlin's `copy()` does. Every instance `lazy` property keeps its
hidden `name#lazy` flag, which `__clone` clears, so the `??=` form for a
non-nullable one is gone. Section 6.5 says a throwing body keeps nothing and
runs again, and that a copy keeps no `lazy` value. Section 6.4 says a copy
creates its own behaviors.

Engine: behaviors.phpt (a `with` copy and a `clone` each count apart) and
lazy.phpt (`Square.grown` gives "9 16", a cloned `Plan` computes again).
…_types

Review finding 5: a PHP# parameter that takes its type argument's type where
the method it overrides erases the type parameter, as `handle(Order $item)`
of a `Handler<Order>`, was declared with no PHP type and checked from the
method's metadata. Reflection reported no type, so a framework that finds a
listener's event from its parameter's type found nothing, and the check
refused `5` for a `string` even from a caller without `strict_types`.

The parameter now keeps its PHP type and carries `ZEND_PARAM_WIDENED`, which
the compiler stores as `_ZEND_IS_WIDENED_BIT` in its `arg_info`, and
`zend_do_perform_arg_type_hint_check` skips the variance check for it. Every
call checks the type as PHP checks any typed parameter. Plain PHP can't set
the bit: it is `ZEND_ACC_ABSTRACT`'s, which PHP refuses on a parameter.

Engine: handlers.phpt reflects `Handlers\Order` from `OrderHandler::handle`,
coerces `5` to "5" without `strict_types`, and refuses it with them.
…stant

Review finding 2: the bridge set each static whose initial value isn't
constant in a `Closure::bind` call after the class, which runs when the file
runs. Opcache preloading runs the file once at startup, so every request saw
the static unset: "Typed static property must not be accessed before
initialization".

The bridge now declares the values in the class's hidden private static
method `#statics`. The engine's new `zend_class_init_sharp_statics` runs it
once each request, when the request first builds the class's statics, after
their constant defaults: from `zend_class_init_statics` when the defaults are
already evaluated, else from `zend_update_class_constants` once it has
evaluated them. A `#statics` the class inherits never runs for it. A value
that throws fails that first use, and the static stays unset.

So a static's initial value runs when a request first uses the class's
statics, Queue 12's "once, when the class is first used". Section 6 now says
so. An observed static's observer runs then too, so overrides.phpt prints
"label start" at `Tally`'s first use.

Engine: preloaded.phpt preloads `Preloaded\Registry` with
`opcache.preload`, and overrides.phpt adds `Faulty`, whose initial value
throws.
…ior takes its type arguments

Review finding 4. A behavior's `get` and `set` are the property's
accessors, so each may have any effect, and a read or write of the property
carries it:

- `Sharp\Behavior` declares `get` and `set` with no `uses`, which refused
  every effectful implementation as impure. `accepts_any_effect` frees them,
  as `runs_listeners` freed `Sharp\Dispatcher::dispatch`, the predicate it
  replaces.
- `effects::summary::record_behaviors` gives a behavior property's `get` and
  `set` summaries that call each behavior's, on the behavior `this` keeps.
  A read then carries `get`'s effect, so a method that must be pure and reads
  the property is refused naming it, and a behavior `get` that writes its
  own fields is refused as any getter writing `this` is. `set` writes them.
- The effects recorder named an accessor only when the property's PHP
  metadata listed a hook, which a PHP# `get; set;` never does. It now names
  every property's accessor, and a call of a body without a summary still
  adds nothing.

`via` names a type, so a generic behavior takes its type arguments as every
type does: `PropertyBehaviorList.behaviors` holds `Hint`s, the name walker
resolves them as any type, semantics refuses one that names no class, the
analyzer checks `Logged<string>` against `Behavior<string>` and records its
type arguments as it records a generic `new`'s, and the bridge's `new`
carries them under `SHARP_TYPE_ARGS`.

Rows: the analyzer's effectful, getter and pure-method rows and its generic
row, the semantics refusal of `via string`, the parser's `via Logged<string>`,
the bridge's `new \App\Kept<int>()`, and behaviors.phpt's `Kept<int>`.
Master's enum cases and sealed interfaces took metadata bits 55 and 56, so
`INTERNAL_SET`, `PROJECT`, `INTERNAL_REACH` and `FIELD` move to bits 57 to
60. `Types::is_widened` and master's function types sit side by side.
Master's emit row takes this branch's `announces` law, and master's getter
row this branch's `getter-writes-this` wording. Three whole-tree bridge rows
take master's return-type `SHARP_TYPE_ARGS` on user methods.
Jordan's ruling, Queue 16: "we want consistency". A `T?` field or property
with storage writes `= null` like any other starting value, or every path
through the constructor sets it, or it is the error a non-nullable member
gets, naming both fixes. Classes now match structs, and there is no default
filler such as `default(T)`.

- The codex gives a `T?` member no `null` default (`sharp_null_default`
  goes), and the bridge lowers none (`is_null_by_default` goes).
- `check_get_only_initialization` holds fields too, nullable or not, so
  `private int count;` with no value and no constructor is refused.
- A static with storage needs an initial value whatever its type:
  "Give `misses` an initial value: no constructor sets a static."
- PHP's own `check_property_initialization`, which offers "make the type
  nullable", runs on PHP only, so a PHP# member gets one error with the two
  fixes the ruling names.

Swept: section 6's rule and its `nullable-members` and
`static-initial-values` examples, the section 14 and 29 examples that
declared function fields without a value, the spec-examples guide, every
analyzer, semantics and bridge fixture, the engine fixtures `Counter`,
`Larder`, `Overrides`, `Positions`, `TypeArgumentsCalls` and
`TypeArgumentsChecks`, and the harness's `Product`.

Rows seen failing first: a field and a settable property
(`a_nullable_member_has_no_implicit_starting_value`) and a static
(`a_static_needs_an_initial_value_whatever_its_type`).
…fills the storage

Jordan accepted both, Queues 17 and 18. No code that can read the object
runs before the object is built: an initial value can't read `this`, it
fills the storage without running a `set` body, constant or not, and
`willSet` and `didSet` run only once the constructor returns.

- Observers run on every write after the constructor returns, an object
  initializer's included. The initial value, a write while a constructor
  or a named constructor runs (a method it calls included) and the values
  a `with` copy is written with run none. A static's initial value runs
  none, and every later write does.
- `field` in `willSet` reads the value the write replaces, so its "not
  supported yet" refusal goes.
- An initial value never runs a `set` body: a constant one stays PHP's
  default, a static's other one is a storage write in `#statics`, and an
  instance one's other one is PHP's `ReflectionProperty::setRawValue` at
  the start of the constructor when the property has a `set` hook. The
  "not supported yet" refusal of a computed initial value beside a `set`
  body goes. A behavior's `set` still processes an initial value.

Engine: `Sharp\Internal\building($object)` tells whether an object is
still being built. A frame up the stack runs one of its constructors
(`ZEND_ACC_CTOR`) or a named constructor's closure on it
(`ZEND_ACC_SHARP_BUILDS`, function flag bit 30, which the bridge sets), or
`clone()` is writing a `with` copy's values (`IS_OBJ_SHARP_BUILDING`,
object extra flag bit 29). An instance property's `set` hook asks it once
per write and runs each observer only when the object is built.

The effect summaries match: a write of `this` in a constructor or a named
constructor carries no observer's effects.

`Property::is_observed` goes: an observer no longer moves an initial value
into the constructor or `#statics`.

Rows: `observers.phpt` (a constructor write runs no observer and runs
`set`, a later write runs both with `field` in `willSet` the old value, a
named constructor and a `with` copy run none, an object initializer runs
them, a constant and a computed initial value skip `set`, a static's
initial value runs none), `behaviors.phpt` (a behavior trims an initial
value), the analyzer's observer typing and effects rows, the semantics
rows, and the bridge's observer, static and named constructor trees.
A behavior that names no class reaches the analyzer after semantics'
error, so the analyzer checks nothing more of it. The defaults that only a
non-object behavior type or a property outside a class could reach are
`unreachable!`: a class written as a type is a named object, and a
property is analyzed in its class's scope.
Queue 19. An object isn't built until its object initializer ends: the
initializer may set `init` properties and must set every `required` one,
so an observer there could read a `required` property not set yet. Its
writes now run `set` and `init` bodies and no observer, as a
constructor's do.

Function flag bit 30 goes back to php-src. `ZEND_ACC_SHARP_BUILDS` took
the last free function flag for one job, and an upstream release that
claims bit 30 would collide with it. The bridge controls both a named
constructor's body and an object initializer, so both now mark the object
itself: `Sharp\Internal\build($object, $body, ...$arguments)` sets
`IS_OBJ_SHARP_BUILDING`, runs the body bound to the object as
`Closure::call` does, and puts back the mark it found whether the body
returns or throws. `Sharp\Internal\building` keeps the `ZEND_ACC_CTOR`
stack walk, because plain PHP code also runs `new` on a PHP# class. A
`with` copy keeps `Closure::call`, since `clone()` marks the copy.

`check_get_only_initialization` becomes `check_storage_initialization`,
as it checks every field and property with storage.

Rows in `observers.phpt`: an initializer's write runs no observer and a
later write does, a named constructor whose body throws puts the mark
back, and an initializer inside a named constructor leaves both objects
built once it returns. Bridge trees: the named constructor rows and the
initializer row.
@heyJordanParker
heyJordanParker merged commit 02c05cb into master Oct 15, 2026
22 checks passed
@heyJordanParker
heyJordanParker deleted the feat/properties branch November 3, 2026 22:08
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.

1 participant