Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:16975 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 1518 invoked by uid 1010); 28 Jun 2005 23:18:00 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 1503 invoked from network); 28 Jun 2005 23:18:00 -0000 Received: from unknown (HELO akbkhome.com) (127.0.0.1) by localhost with SMTP; 28 Jun 2005 23:18:00 -0000 X-Host-Fingerprint: 202.81.246.113 246-113.netfront.net Received: from ([202.81.246.113:37769] helo=akbkhome.com) by pb1.pair.com (ecelerity 1.2 r(5656M)) with SMTP id E4/CA-00424-5AAD1C24 for ; Tue, 28 Jun 2005 19:17:58 -0400 Received: from [192.168.0.184] (helo=alanportable2.hklc.com) by akbkhome.com with esmtp (Exim 4.44) id 1DnPXr-0005gf-4S; Wed, 29 Jun 2005 07:31:12 +0800 To: James Crumpton Cc: internals@lists.php.net In-Reply-To: <42C1C1D3.7060601@safesearching.com> References: <42C1C1D3.7060601@safesearching.com> Content-Type: text/plain Date: Wed, 29 Jun 2005 07:22:04 +0800 Message-ID: <1120000924.1128.15.camel@alanportable2.hklc.com> Mime-Version: 1.0 X-Mailer: Evolution 2.0.4 Content-Transfer-Encoding: 7bit X-ACL-Warn: "cleared badlog" Subject: Re: [PHP-DEV] class_exists and __autoload From: alan@akbkhome.com (Alan Knowles) This yet again illustrates the sillyness of autoload, if we are going to have a feature that autoloads classes it should be explicit in it's usage: autoload("Class_Name"); defaults to loading Class_Name.php ? if __autoload exists, it calls that.. adding all sorts of magic to the Class operators is digging a hole that you will be continually answering... Ok - got up the wrong side of bed this morning ;) Regards Alan On Tue, 2005-06-28 at 14:32 -0700, James Crumpton wrote: > I opened a bug (http://bugs.php.net/bug.php?id=33459) to report an issue with > the default behavior of class_exists calling __autoload in PHP5. The bug was > marked as bogus, and basically stated that it's PEARs problem. After responding, > the bug can now longer be searched for. > > I believe this still requires some attention as the issues around it are very > similar in nature to the ones with instanceOf and __autoload. (See > http://news.php.net/php.internals/16746) > > Basically, adding __autoload to any script using > Calendar/DB_DataObject/SOAP/Validate (just to name a few) will throw a fatal error. > > Example being: > > require_once('Calendar/Calendar.php'); > > $cal = new Calendar(); > > function __autoload($name) { > require_once($name); > } > ?> > > This isn't specific to PEAR however... any script/class that uses > !class_exists() to load a file not in 'include_path' will fail when __autoload > is used in conjunction. > > Furthermore, I fail to see why such a "feature" is in place when it makes all > existing if(!class_exists()) {} constructs worthless. > > if (!class_exists($className)) { > // ... do something interesting ... > // well, with autoload defined, this block will never be reached. > // autoload will either load the class and the above condition will > // be false, or autoload will throw a fatal error and we never get here > } > > I just don't understand the logic behind throwing a fatal error when I'm writing > code to try and prevent one from occurring. > > I realize a second parameter is available to class_exists that can be set to > false, which will prevent __autoload from being called, but developers don't > always have the luxury of modifying other peoples code to make it work they way > they intended it (such is the case with PEAR classes). > > If someone really wants this behavior (though I can't understand for life of me > why), then allow them to pass TRUE as the second parameter, but leave the > default be false. Or at the very least let autoload return false, so that the > rest of the script can do it's thing... or maybe allow for a php.ini option to > set the default behavior to false (though this option can make some scripts less > portable). > > -james >