[PATCH] in_class_exists() for detecting __autoload() called by class_exists() and interface_exists()

From: Date: Wed, 03 Oct 2007 06:21:50 +0000
Subject: [PATCH] in_class_exists() for detecting __autoload() called by class_exists() and interface_exists()
Groups: php.internals 
Request: Send a blank email to internals+get-32585@lists.php.net to get a copy of this message
Hi again, The attached patches for PHP 5.3 and PHP 6 add in_class_exists(). The function is intended to be used in __autoload(). The following test script demonstrates its usage: <?php var_dump(in_class_exists('test')); function __autoload($class) { var_dump(in_class_exists($class)); eval ('class ' . $class . ' {}'); } $a = new Bungalow; // autoload called, not because of class_exists(), bool(false) class_exists('test'); // autoload called because of class_exists(), bool(true) class_exists('test'); // class exists, no autoload, no output $a = new test; // autoload not called, no output $a = new Another; // autoload called, not because of class_exists(), bool(false) ?> outputting: bool(false) bool(false) bool(true) bool(false) The purpose is to allow an autoload handler to detect whether it is safe to use die() or some other method of terminating execution. A user calling class_exists() clearly expects a return from autoload, whereas a user instantiating an object will expect a fatal error if the class cannot be found. This is useful for PEAR2 as a means of displaying helpful information on locating missing class files only in cases where a fatal error would result anyways. Thanks, Greg

« previous php.internals (#32585) next »