php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80721 class_exists produce PHP Fatal error
Submitted: 2021-02-07 11:00 UTC Modified: 2021-02-07 11:12 UTC
From: parviz at engineer dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 7.4.8 OS: Windows 10 Pro 64 Bit
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: parviz at engineer dot com
New email:
PHP Version: OS:

 

 [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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-02-07 11:05 UTC] 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:07 UTC] parviz at engineer dot com
-PHP Version: 7.4Git-2021-02-07 (Git) +PHP Version: 7.4.8
 [2021-02-07 11:07 UTC] parviz at engineer dot com
PHP Version: 7.4.8
 [2021-02-07 11:12 UTC] 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:12 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2021-02-07 11:12 UTC] requinix@php.net
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.


 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Wed Jul 06 01:05:44 2022 UTC