Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:25584 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 48849 invoked by uid 1010); 10 Sep 2006 14:15:20 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 48833 invoked from network); 10 Sep 2006 14:15:20 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Sep 2006 14:15:20 -0000 Received: from [127.0.0.1] ([127.0.0.1:29001]) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ECSTREAM id C6/40-46429-7FD14054 for ; Sun, 10 Sep 2006 10:15:19 -0400 Authentication-Results: pb1.pair.com smtp.mail=tslettebo@broadpark.no; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=tslettebo@broadpark.no; sender-id=unknown Received-SPF: error (pb1.pair.com: domain broadpark.no from 80.202.4.58 cause and error) X-PHP-List-Original-Sender: tslettebo@broadpark.no X-Host-Fingerprint: 80.202.4.58 osl1smout1.broadpark.no Solaris 9 Received: from [80.202.4.58] ([80.202.4.58:60072] helo=osl1smout1.broadpark.no) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7B/51-21785-EC514054 for ; Sun, 10 Sep 2006 09:40:31 -0400 Received: from osl1sminn1.broadpark.no ([80.202.4.59]) by osl1smout1.broadpark.no (Sun Java System Messaging Server 6.1 HotFix 0.05 (built Oct 21 2004)) with ESMTP id <0J5D00AR5MWCWDA0@osl1smout1.broadpark.no> for internals@lists.php.net; Sun, 10 Sep 2006 14:33:48 +0200 (CEST) Received: from pc ([80.203.129.59]) by osl1sminn1.broadpark.no (Sun Java System Messaging Server 6.1 HotFix 0.05 (built Oct 21 2004)) with SMTP id <0J5D00FURMWC9RB0@osl1sminn1.broadpark.no> for internals@lists.php.net; Sun, 10 Sep 2006 14:33:48 +0200 (CEST) Date: Sun, 10 Sep 2006 14:33:59 +0200 To: internals@lists.php.net Message-ID: <015801c6d4d5$6440d1d0$9a02a8c0@pc> MIME-version: 1.0 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1807 X-Mailer: Microsoft Outlook Express 6.00.2800.1807 Content-type: text/plain; charset=iso-8859-1 Content-transfer-encoding: 7BIT X-Priority: 3 X-MSMail-priority: Normal Subject: __autoloading and functions From: tslettebo@broadpark.no (=?iso-8859-1?Q?Terje_Sletteb=F8?=) Hi all. I don't know if this has been discussed before (I've not found it from doing a search), but if it has, please provide me with a link to the discussion. __autoload() is very convenient, but it has one problem: While classes defined in the __autoload() function (via an include) are accessible globally, any functions being included are not accessible outside the __autoload() function, making them completely inaccessible to the rest of the system. This means that if you have a file containing a class, as well as one or more associated functions, you won't be able to use the functions, if the file containing the class and functions is loaded using autoloading... I've not found a workaround for this (except reintroducing include_once/require_once, which defeats the whole purpose of autoloading...), are others also experiencing problems with this, and if not, do you a) not use any functions, or b) manage some other way? Has there been considerations for solving this in some way? Example: --- email_address.php --- class EmailAddress { public function __construct($address) { ... } // Check if string contains a valid email address .... private $address; } function email_address($address) { return new EmailAddress($address); } --------------------------------- You may then use this like: $address=email_address(); to make the conversion to EmailAddress less "obtrusive" (simulating implicit conversion to user-defined type). However, this doesn't work with autoloading, so you have to either manually include the above file, or use "new" directly: $address=new EmailAddress(); In other words, this function is not a candidate for making it a method. The problem in this particular example would go away if there was a way to implicitly convert from fundamental types to user-defined types, but that's another discussion... Regards, Terje