|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2021-02-07 11:00 UTC] parviz at engineer dot com
Description:
------------
when we declare a variable in a class that and initialize it like in 'Test script', and than use class_exists with that class name, it will produce PHP Fatal error
Test script:
---------------
<?php
class TestClass {
public object $testVar = (object) [
'status' => false
];
}
var_dump( class_exists('TestClass') );
Expected result:
----------------
return bool that tell us the class exists or not
Actual result:
--------------
Fatal error: Constant expression contains invalid operations in D:\XAMPP\htdocs\test.php on line 4
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 07:00:01 2025 UTC |
you can't do type-casting at that level of code, there are also other limitations besides typed-properties in a class definition virtually forever class TestClass { public int $testVar = (int)'1'; } $x = new TestClass;