php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46341 defined() doesn't work properly.
Submitted: 2008-10-19 13:59 UTC Modified: 2008-10-23 21:36 UTC
From: PrzemekG_ at poczta dot onet dot pl Assigned: iliaa (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.2.6 OS: GNU/Debian
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: PrzemekG_ at poczta dot onet dot pl
New email:
PHP Version: OS:

 

 [2008-10-19 13:59 UTC] PrzemekG_ at poczta dot onet dot pl
Description:
------------
People use defined() to check if a constant is defined so they can later use constant() without any warning or error.

I found these bugs:
1. defined() doesn't forward exceptions
2. defined() try to load class from an invalid constant name (false:::::)
3. produce invalid error line white raising an error if autoloader thrown an exception.

There should be a $autoload param like in class_exists() and interface_exists().


Reproduce code:
---------------
<?
function autoloader($class) {
	throw new Exception(); // line 3
}

spl_autoload_register('autoloader');

function foo() {
	defined('false:::::::'); // line 9
	$a = 10;
	$b = 11;
} // line 12

foo(); // line 14
?>

Expected result:
----------------
From PHP 5.1.2:

Fatal error: Uncaught exception 'Exception' in /root/x.php:3
Stack trace:
#0 [internal function]: autoloader('false')
#1 [internal function]: spl_autoload_call('false')
#2 /root/x.php(9): defined('false:::::::')
#3 /root/x.php(14): foo()
#4 {main}
  thrown in /root/x.php on line 3


Actual result:
--------------
From PHP 5.2.6:

Fatal error: Class 'false' not found in /root/workspace.appserv/XAS/bugTest.php on line 12

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-10-19 18:25 UTC] iliaa@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Apr 29 01:01:30 2024 UTC