Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:25586 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 56383 invoked by uid 1010); 10 Sep 2006 14:48:31 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 56368 invoked from network); 10 Sep 2006 14:48:31 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Sep 2006 14:48:31 -0000 Authentication-Results: pb1.pair.com header.from=hannes.magnusson@gmail.com; sender-id=pass; domainkeys=good Authentication-Results: pb1.pair.com smtp.mail=hannes.magnusson@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 64.233.182.191 as permitted sender) DomainKey-Status: good X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: hannes.magnusson@gmail.com X-Host-Fingerprint: 64.233.182.191 nf-out-0910.google.com Linux 2.4/2.6 Received: from [64.233.182.191] ([64.233.182.191:63904] helo=nf-out-0910.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5C/51-46429-DB524054 for ; Sun, 10 Sep 2006 10:48:31 -0400 Received: by nf-out-0910.google.com with SMTP id y25so1125597nfb for ; Sun, 10 Sep 2006 07:48:27 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=FtZKYcWngj4aqgoJnuSsX+oktpm374m+9VZhimlz3lMbt7TzwqtXFfBYa8nWrFetkWInjiiXQagJAqBIDdHW9FbIGio0UkGsg/1r0D8y5FvVv/sg0JaQ+sjmb8NMPsdcU7RpY+cBE6Wn9DiyZvS5iaRxiszrbxUwec2MddxR95Y= Received: by 10.49.8.15 with SMTP id l15mr6782013nfi; Sun, 10 Sep 2006 07:48:26 -0700 (PDT) Received: by 10.48.212.14 with HTTP; Sun, 10 Sep 2006 07:48:26 -0700 (PDT) Message-ID: <7f3ed2c30609100748g396c957cm2c5f0cd5e2aae28b@mail.gmail.com> Date: Sun, 10 Sep 2006 16:48:26 +0200 To: "=?ISO-8859-1?Q?Terje_Sletteb=F8?=" Cc: internals@lists.php.net In-Reply-To: <7f3ed2c30609100744x7a5d4fdfs9601ae4671b351d3@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <015801c6d4d5$6440d1d0$9a02a8c0@pc> <7f3ed2c30609100744x7a5d4fdfs9601ae4671b351d3@mail.gmail.com> Subject: Re: __autoloading and functions From: hannes.magnusson@gmail.com ("Hannes Magnusson") On 9/10/06, Hannes Magnusson wrote: > Hello Terje > > What are you talking about? > --class.php-- > class foo { > } > > function bar() { > print "Hello World\n"; > } > > --foo.php-- > function __autoload($class) { > include "class.php"; > } > > new foo(); > bar(); > > print "hello world";... Gah. I meant to say "Prints out 'hello world'" > > -Hannes > > On 9/10/06, Terje Sletteb=F8 wrote: > > 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 i= f > > 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=3Demail_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=3Dnew 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 > > > > -- > > PHP Internals - PHP Runtime Development Mailing List > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > >