Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51230 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 11241 invoked from network); 6 Jan 2011 01:51:55 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Jan 2011 01:51:55 -0000 Authentication-Results: pb1.pair.com header.from=john.lesueur@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=john.lesueur@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.170 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: john.lesueur@gmail.com X-Host-Fingerprint: 209.85.216.170 mail-qy0-f170.google.com Received: from [209.85.216.170] ([209.85.216.170:37281] helo=mail-qy0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 97/17-10843-A30252D4 for ; Wed, 05 Jan 2011 20:51:55 -0500 Received: by qyk10 with SMTP id 10so16924677qyk.8 for ; Wed, 05 Jan 2011 17:51:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type; bh=oDI01GZuJUvTsSWEDW1PsL413zU1Jse5GhyKOMTSoN0=; b=do0rCilaDGjR3XS3d5zW6lvP+aRHfgfK5GhRWtlcq5YyrsVXzZzfrHOfcySw5WX2Al jr0sIW4AI4jL8/cTtkDuHu9tV6DMEWmy4J5UWzf3Fwo5YxmwWAk2SvfmmS8EAVs24JDl 03Wf1e8Nyx9Y5mgN/lZYZH6i8hOIE8aUVRCSY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=TC5dx+CRCWn2zpdqXaUpSdz2dXDPEShVBI9wrkORr5rtDfhubmja59yebeD9IvuqT9 872WmWxZ8Frot79hbdZ0DxxWD7XFHGw5AcwsAdDXV7zku9AI68WAw55k2FNJ7abvS4mB c6W42wKBdKySSRMlry3meBco9yQ79Vqj7/vk8= MIME-Version: 1.0 Received: by 10.224.67.82 with SMTP id q18mr22268284qai.358.1294278711350; Wed, 05 Jan 2011 17:51:51 -0800 (PST) Received: by 10.220.5.196 with HTTP; Wed, 5 Jan 2011 17:51:51 -0800 (PST) In-Reply-To: <1294276068.10675.3.camel@guybrush> References: <1294276068.10675.3.camel@guybrush> Date: Wed, 5 Jan 2011 18:51:51 -0700 Message-ID: To: =?ISO-8859-1?Q?Johannes_Schl=FCter?= Cc: Martin Scotta , internals@lists.php.net Content-Type: multipart/alternative; boundary=0015175cbac0d49546049923be2f Subject: Re: [PHP-DEV] RFC: about class names as values From: john.lesueur@gmail.com (John LeSueur) --0015175cbac0d49546049923be2f Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 2011/1/5 Johannes Schl=FCter > On Wed, 2011-01-05 at 21:53 -0300, Martin Scotta wrote: > > $obj =3D newInstance( MyClass ); // notice. undefined constant MyClass > > This describes the major change with your idea. > > What happens if a constant MyClass exists? > > Another question is something like this: > > function factory($class) { > return new $class(); > } > > factory( SomeClass ); > ?> > > > To proper support this we'd have to make classes first class elements. > For making this consistent it would make sense to make functions first > class elements. And best drop the $ in front of variables and create a > new language. Everything else becomes a mess. > > johannes > > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > I think he's actually proposing creating for each class the magic class constant CLASS, so your example becomes: This is actually doable without a magic class constant, but requires a function or class constant to be declared in each class. Perhaps this could be simplified with traits, if __NAMESPACE__ and __CLASS_= _ work in traits that way. In fact, that's an interesting question, what is __NAMESPACE__ in a trait defined in one namespace, then used in a class in = a different namespace? I think the point is that the factory function could exist without any knowledge of the namespaces of the classes it would work on. Then, somewher= e else where the class has been aliased or is otherwise accessible without th= e full namespace path, the developer wouldn't need to specify the full namespace path to the factory, but could ask the class itself what it's ful= l namespace path was. I don't know that I agree with the idea, but I don't think it requires making classes first class elements. John --0015175cbac0d49546049923be2f--