Bug #80721 [Opn->Nab]: class_exists produce PHP Fatal error
Edit report at https://bugs.php.net/bug.php?id=80721&edit=1
ID: 80721
Updated by: requinix@php.net
Reported by: parviz at engineer dot com
Summary: class_exists produce PHP Fatal error
-Status: Open
+Status: Not a bug
Type: Bug
Package: *General Issues
Operating System: Windows 10 Pro 64 Bit
PHP Version: 7.4.8
Block user comment: N
Private report: N
New Comment:
Sorry, but your problem does not imply a bug in PHP itself. For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system
is not the
appropriate forum for asking support questions. Due to the volume
of reports we can not explain in detail here why your report is not
a bug. The support channels will be able to provide an explanation
for you.
Thank you for your interest in PHP.
Previous Comments:
------------------------------------------------------------------------
[2021-02-07 11:12:21] rtrtrtrtrt at dfdfdfdf dot dfd35
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;
------------------------------------------------------------------------
[2021-02-07 11:07:05] parviz at engineer dot com
PHP Version: 7.4.8
------------------------------------------------------------------------
[2021-02-07 11:05:57] rtrtrtrtrt at dfdfdfdf dot dfd35
jesus christ your code is nonsense and results ina compile time error, class_exists() is not called
at all when invalid code is loaded and the script get killed
php -l test.php
Fatal error: Constant expression contains invalid operations in test.php on line 4
Errors parsing test.php
------------------------------------------------------------------------
[2021-02-07 11:00:00] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80721&edit=1
Thread (5 messages)