|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2021-05-12 10:27 UTC] nikic@php.net
-Status: Open
+Status: Not a bug
[2021-05-12 10:27 UTC] nikic@php.net
[2021-05-12 11:06 UTC] bugs-php at daniel-siepmann dot de
[2021-05-17 14:12 UTC] girgias@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 04:00:01 2025 UTC |
Description: ------------ Given a script without declare_strict but a method with defined return type. The method returns an integer but the stored value might be a string. I would expect PHP to do a type cast which works in general. But it does not work with example string. Test script: --------------- class Test { protected $property; public function __construct() { $this->property = 10; } public function getProperty(): ?int { return $this->property; } public function setProperty($value) { $this->property = $value; } } $subject = new Test; var_dump($subject->getProperty()); // works $subject->setProperty((int) '{$PID.event.import.ismf.storagePid}'); // works var_dump($subject->getProperty()); // works $subject->setProperty('{$PID.event.import.ismf.storagePid}'); // works var_dump($subject->getProperty()); // breaks Expected result: ---------------- I would expect the last line to return the integer 0 instead of an TypeError. Actual result: -------------- The script fails with PHP Fatal error: Uncaught TypeError: Return value of Test::getProperty() must be of the type int, string returned