Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:25585 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 55083 invoked by uid 1010); 10 Sep 2006 14:44:24 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 55068 invoked from network); 10 Sep 2006 14:44:24 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Sep 2006 14:44:24 -0000 Authentication-Results: pb1.pair.com smtp.mail=hannes.magnusson@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=hannes.magnusson@gmail.com; sender-id=pass; domainkeys=good 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:60971] helo=nf-out-0910.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7E/11-46429-7C424054 for ; Sun, 10 Sep 2006 10:44:24 -0400 Received: by nf-out-0910.google.com with SMTP id y25so1125098nfb for ; Sun, 10 Sep 2006 07:44:20 -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=EAgO6cbY5x86FxP0fHfJSp+Z571Xn3q3lDxPeWZL4rKuUDL9MB5oijZE1usdEr+CbxnBTrvLe8lwQ+k/DBH+5M3S9CBKjzLcjk9DFJXEN+D4JsPD82B6StsOdTe5tREAqkNQ131LjzWhbSXEzG97iQjAMPlM7mzsf4RXDzhOiSU= Received: by 10.49.41.12 with SMTP id t12mr6781507nfj; Sun, 10 Sep 2006 07:44:20 -0700 (PDT) Received: by 10.48.212.14 with HTTP; Sun, 10 Sep 2006 07:44:20 -0700 (PDT) Message-ID: <7f3ed2c30609100744x7a5d4fdfs9601ae4671b351d3@mail.gmail.com> Date: Sun, 10 Sep 2006 16:44:20 +0200 To: "=?ISO-8859-1?Q?Terje_Sletteb=F8?=" Cc: internals@lists.php.net In-Reply-To: <015801c6d4d5$6440d1d0$9a02a8c0@pc> 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> Subject: Re: __autoloading and functions From: hannes.magnusson@gmail.com ("Hannes Magnusson") Hello Terje What are you talking about? --class.php-- wrote: > Hi all. > > I don't know if this has been discussed before (I've not found it from do= ing > 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 wel= l > as one or more associated functions, you won't be able to use the functio= ns, > 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 contai= ns > 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 impli= cit > conversion to user-defined type). > > However, this doesn't work with autoloading, so you have to either manual= ly > 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 t= o > 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 > >