Exception::$message can't be extends with string type
Open
Nobody has claimed this yet.
- Dominant language
- XML
- Stars
- 596
- Forks
- 890
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 55
Description
Description
Documentation book
The PHP book describes Exception class as follows:
https://www.php.net/manual/en/class.exception.php
class Exception implements Throwable {
/* Properties */
protected string $message= "";
[...]
}
Extending it:
<?php
class AException extends \Exception
{
protected $message = 'New Default Message';
}
class BException extends \Exception
{
protected string $message = 'New Default Message';
}
Resulted in this output:
Fatal error: Type of BException::$message must not be defined (as in class Exception)
But I expected this output instead:
No error. Or an error for class A, not class B.
PHP Version
PHP 8.2.1
Operating System
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 with the Exception class page linked in the issue and reproduce the PHP 8.2.1 examples to confirm the documented property type and inheritance behavior. Done means the documentation accurately explains the behavior and the examples no longer contradict the observed result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100