Req #73604 [Opn]: Excplicit type cast for class constants produces error

From: Date: Fri, 25 Nov 2016 17:57:40 +0000
Subject: 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-205641@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: stas@php.net Reported by: anatoly dot pashin at gmail dot com Summary: Excplicit type cast for class constants produces error Status: Open Type: Feature/Change Request Package: Scripting Engine problem PHP Version: 7.0.13 Block user comment: N Private report: N New Comment: Some non-object casts can depend on run-time environment, such as casting double to string (depends on precision). Previous Comments: ------------------------------------------------------------------------ [2016-11-25 17:17:46] nikic@php.net 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. ------------------------------------------------------------------------ [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

« previous php.bugs (#205641) next »