Req #70604 [NEW]: Magic Integer casting + NULL cast
| From: | jodminster at gmx dot net | Date: | Wed, 30 Sep 2015 08:47:27 +0000 |
| Subject: | Req #70604 [NEW]: Magic Integer casting + NULL cast | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-196309@lists.php.net to get a copy of this message | ||
From: jodminster at gmx dot net
Operating system:
PHP version: Irrelevant
Package: *General Issues
Bug Type: Feature/Change Request
Bug description:Magic Integer casting + NULL cast
Description:
------------
Analog to __toString() a __toInt() method.
Additionally allow NULL as a valid return value for casting methods.
Test script:
---------------
class test {
private $value;
function __construct($value = null) {
$this->value = $value;
}
function __toString() {
return $this->value ? (string) $this->value : $this->value;
}
function __toInt() {
return $this->value ? (int) $this->value : $this->value;
}
}
(string)(new test()) === null;
(string)(new test('1')) === '1';
(string)(new test(1)) === '1';
(int)(new test()) === null;
(int)(new test('1') === 1;
(int)(new test(1) === 1;
Expected result:
----------------
6 x true
Actual result:
--------------
* Catchable fatal error: Method test::__toString() must return a string
value in php shell code on line 1
*__toInt is never called
--
Edit bug report at https://bugs.php.net/bug.php?id=70604&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=70604&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=70604&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=70604&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=70604&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=70604&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=70604&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=70604&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=70604&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=70604&r=support
Expected behavior: https://bugs.php.net/fix.php?id=70604&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=70604&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=70604&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=70604&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70604&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=70604&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=70604&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=70604&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=70604&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=70604&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=70604&r=mysqlcfg