php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53086 require fails in error handler when E_STRICT is emitted from namespace class
Submitted: 2010-10-17 01:44 UTC Modified: 2016-05-10 07:31 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: cmanley at xs4all dot nl Assigned: dmitry (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.6.21 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: cmanley at xs4all dot nl
New email:
PHP Version: OS:

 

 [2010-10-17 01:44 UTC] cmanley at xs4all dot nl
Description:
------------
When an E_STRICT error is emitted from a class within a namespace and this is 
caught in a custom error handler, then require_once() fails.

To demonstrate this bug, I created a minimal test below. It consists of 3 files. 
Place them in a directory and execute test.php from the command line.

Test script:
---------------
************* file test.php ******************
<?php
error_reporting(E_ALL | E_STRICT);

// Custom error handler.
function handle_error($code, $message, $file, $line, $context) {
	$code = $code & error_reporting();
	if ($code == 0) { // skip @ suppressed errors.
		return;
	}
	$errors = array(
		E_ERROR				=> 'E_ERROR',
		E_WARNING			=> 'E_WARNING',
		E_PARSE				=> 'E_PARSE',
		E_NOTICE			=> 'E_NOTICE',
		E_CORE_ERROR		=> 'E_CORE_ERROR',
		E_CORE_WARNING		=> 'E_CORE_WARNING',
		E_COMPILE_ERROR		=> 'E_COMPILE_ERROR',
		E_COMPILE_WARNING	=> 'E_COMPILE_WARNING',
		E_USER_ERROR		=> 'E_USER_ERROR',
		E_USER_WARNING		=> 'E_USER_WARNING',
		E_USER_NOTICE		=> 'E_USER_NOTICE',
		E_STRICT			=> 'E_STRICT',
		E_DEPRECATED		=> 'E_DEPRECATED',
	);
	if (array_key_exists($code, $errors)) {
		$errname = $errors[$code];
	}
	else {
		$errname = $code;
	}
	$error = "Error handler caught $errname with message \"" . $message . '" at ' . $file . ' line ' . $line . ".\n";
	error_log($error);
	require_once('bla.php');
	bla($error);
	return;
}
set_error_handler('handle_error');

// This fails because bla.php can't be required in error handler:
require_once('Abstract.php');



*************** Abstract.php **************
<?php
namespace MyNamespace {
	abstract class AbstractFoo {
		abstract public static function foo(); // PHP 5.3 issues an E_STRICT here about abstract + static, even though it now supports static inheritance.
	}
}




*************** bla.php ******************
<?php
function bla() {
	print "You should see this.\n";
}

Expected result:
----------------
Error handler caught E_STRICT with message "Static function 
MyNamespace\AbstractFoo::foo() should not be abstract" at 
/home/cmanley/0/Abstract.php line 4.

You should see this.

Actual result:
--------------
Error handler caught E_STRICT with message "Static function 
MyNamespace\AbstractFoo::foo() should not be abstract" at 
/home/cmanley/0/Abstract.php line 4.

PHP Fatal error:  Call to undefined function bla() in /home/cmanley/0/Abstract.php 
on line 4

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-10-19 13:06 UTC] uramihsayibok at gmail dot com
Not sure if this should be a bug or whether it's just unexpected behavior.

The file is included fine. bla() exists. But it exists in the MyNamespace 
namespace. So
  require_once('bla.php');
  MyNamespace\bla();
  return;
works.

The question is, then, whether the error handler should be in the global 
namespace, the namespace it was originally defined in, or the namespace of the 
code triggering the error.
 [2010-10-19 13:53 UTC] cmanley at xs4all dot nl
Well whatever it is, one doesn't have to be Nostradamus to predict that if this isn't changed/fixed that it's going to lead to a lot of namespace horror stories in the future.
 [2013-12-05 19:55 UTC] mike@php.net
-Status: Open +Status: Verified -Package: *General Issues +Package: Scripting Engine problem -Assigned To: +Assigned To: dmitry
 [2016-05-06 14:45 UTC] nikic@php.net
-PHP Version: 5.3.3 +PHP Version: 5.6.21
 [2016-05-06 14:45 UTC] nikic@php.net
This has been fixed in PHP 7.0: https://3v4l.org/TjXg7
 [2016-05-10 07:31 UTC] dmitry@php.net
-Status: Verified +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 20:01:29 2024 UTC