Bug #81036 [NEW]: TypeError is raised instead of implizit type casting
| From: | bugs-php at daniel-siepmann dot de | Date: | Wed, 12 May 2021 10:23:23 +0000 |
| Subject: | Bug #81036 [NEW]: TypeError is raised instead of implizit type casting | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-233811@lists.php.net to get a copy of this message | ||
From: bugs-php at daniel-siepmann dot de
Operating system: Ubuntu
PHP version: 7.4.19
Package: *Programming Data Structures
Bug Type: Bug
Bug description:TypeError is raised instead of implizit type casting
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
--
Edit bug report at https://bugs.php.net/bug.php?id=81036&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=81036&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=81036&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=81036&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=81036&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=81036&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=81036&r=support
Expected behavior: https://bugs.php.net/fix.php?id=81036&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=81036&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=81036&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=81036&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=81036&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=81036&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=81036&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=81036&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=81036&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=81036&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=81036&r=mysqlcfg