Typed properties: the unset() command make property undeclared instead of uninitialized
Nobody has claimed this yet.
- Dominant language
- XML
- Stars
- 596
- Forks
- 890
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 55
Description
Description
The following code:
<?php
class Dummy {
public string $prop;
public function __set($name, $value) {
echo "Property '$name' in undeclared!\n";
$this->$name = $value;
}
}
$dummy = new Dummy;
// This write to uninitialized property - nothing printed
$dummy->prop = 'First attempt';
echo "{$dummy->prop}\n";
unset($dummy->prop);
// This write to **undeclared** property - message is printed
$dummy->prop = 'Second attempt';
echo "{$dummy->prop}\n";
Resulted in this output:
First attempt
Property 'prop' in undeclared!
Second attempt
Live example: https://3v4l.org/0YfXD
But I expected this output instead:
First attempt
Second attempt
The PHP RFC is explicitly say:
If a typed property is
unset(), then it returns to the uninitialized state.
But it's not true, because the unset() command doesn't returns to the uninitialized state but it's just undeclare them and the uninitialized state is simulated at runtime when somebody is trying to read it.
The different is evident when I trying write to property – property in uninitialized state does not call magic __set() method, undeclared property does.
PHP Version
PHP 7.4.0 - 7.4.28, 8.0.1 - 8.0.16, 8.1.0 - 8.1.3
Operating System
No response
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the PHP reproduction in the issue across the listed PHP versions and read the linked typed properties RFC. Confirm how unset() affects subsequent writes and magic __set() calls, then identify the relevant PHP documentation page. Done means the documented behavior and the reported behavior are reconciled, with a regression example or clarification as appropriate.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- documentation
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100