[PHP-BUG] Bug #73604 [NEW]: Excplicit type cast for class constants produces error
[email protected] ("anatoly dot pashin at gmail dot com") Fri, 25 Nov 2016 08:33:25 GMT
| Newsgroups | php.standards |
|---|---|
| Message-ID | <[email protected]> |
From: anatoly dot pashin at gmail dot com
Operating system:
PHP version: 7.0.13
Package: PHP Language Specification
Bug Type: Bug
Bug description:Excplicit type cast for class constants produces error
Description:
------------
Interpreter produces `PHP Fatal error: Constant expression contains
invalid operations in…` because of explicit const value type cast.
But implicit is allowed and works as expected.
Yes, I undestand difference between `+` and `(int)` that `int` will cast
to integer and drop past-float part. But question why that's now allowed
is still present.
Casting plain value rather than array value doesn't work too. Even if
you cast integer to integer.
Test script:
---------------
class Barcode
{
const BARCODE_TYPES = [
(int)\Stickers::BARCODE_TYPE_MEGAORDER,
+\Stickers::BARCODE_TYPE_SHOP_ORDER,
];
}
Expected result:
----------------
All is OK and array value became int casted.
Actual result:
--------------
PHP Fatal error: Constant expression contains invalid operations in…
--
Edit bug report at https://bugs.php.net/bug.php?id=73604&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=73604&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=73604&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=73604&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=73604&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=73604&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=73604&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=73604&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=73604&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=73604&r=support
Expected behavior: https://bugs.php.net/fix.php?id=73604&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=73604&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=73604&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=73604&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=73604&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=73604&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=73604&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=73604&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=73604&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=73604&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=73604&r=mysqlcfg