Bug->Req #73604 [Opn]: Excplicit type cast for class constants produces error
| From: | nikic@php.net | Date: | Fri, 25 Nov 2016 17:17:48 +0000 |
| Subject: | Bug->Req #73604 [Opn]: Excplicit type cast for class constants produces error | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-205639@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=73604&edit=1
ID: 73604
Updated by: nikic@php.net
Reported by: anatoly dot pashin at gmail dot com
Summary: Excplicit type cast for class constants produces
error
Status: Open
-Type: Bug
+Type: Feature/Change Request
-Package: PHP Language Specification
+Package: Scripting Engine problem
PHP Version: 7.0.13
Block user comment: N
Private report: N
New Comment:
Constant expressions only support a limited set of operations. Casts are currently not part of this
set. However, apart from the (object) cast, there is no *specific* reason to disallow them, so
adding support for this shouldn't be a problem.
Previous Comments:
------------------------------------------------------------------------
[2016-11-25 08:33:23] anatoly dot pashin at gmail dot com
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 this bug report at https://bugs.php.net/bug.php?id=73604&edit=1