Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:60100 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 66134 invoked from network); 17 Apr 2012 19:31:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Apr 2012 19:31:11 -0000 Authentication-Results: pb1.pair.com smtp.mail=dragoonis@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=dragoonis@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.170 as permitted sender) X-PHP-List-Original-Sender: dragoonis@gmail.com X-Host-Fingerprint: 209.85.217.170 mail-lb0-f170.google.com Received: from [209.85.217.170] ([209.85.217.170:38419] helo=mail-lb0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AD/C2-03996-DF4CD8F4 for ; Tue, 17 Apr 2012 15:31:11 -0400 Received: by lbbgf7 with SMTP id gf7so5172935lbb.29 for ; Tue, 17 Apr 2012 12:31:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=wqlgbb4AygPkEqfuOMPlDbexIFbGJjqxtaqRlx4QIQ0=; b=GPrB7IaFu7dcp9R8g//NZxyGRGsS7xEZOAMUXaXRrqmz8eqmrHxbAI0hA+csJHtnUS xXv/wyIdD0fKqZLBmek1YrFzl0kY3jjG4QLv3CYF4lfcK0GbodmtRqAO/K/+6nprbW22 mwG1HlGJO4cw3eDHvJ50Pxmgix27gehtR51xstv1iI9iVGNhjFYfQroKk0dE950LuM9y Bgy34LiqKKLhYeQgDxBGSNEpzcm0YZo0MHjaleZs2hrNTL1Q/NYIDrinerknYN37PDrg 7l0FspgqUZk2BWBGNkYLiTeihqQ91IqZKsAzDylb+KAeBHWyIYTLzPHq/PT6Vr6FGonb SPFA== MIME-Version: 1.0 Received: by 10.112.38.68 with SMTP id e4mr7725692lbk.38.1334691066781; Tue, 17 Apr 2012 12:31:06 -0700 (PDT) Received: by 10.152.115.71 with HTTP; Tue, 17 Apr 2012 12:31:06 -0700 (PDT) In-Reply-To: <4F8DC211.70107@hoa-project.net> References: <4F8DC211.70107@hoa-project.net> Date: Tue, 17 Apr 2012 20:31:06 +0100 Message-ID: To: ivan.enderlin@hoa-project.net Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary=485b390f7a06eba27304bde4faa4 Subject: Re: [PHP-DEV] Make require*/include* behave like a function for returning values, and more From: dragoonis@gmail.com (Paul Dragoonis) --485b390f7a06eba27304bde4faa4 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable I don't see any fundamental benefit to having this in PHP. It doesn't work around any current restrictions in the language. It just looks like extra fluffy magic that we could do without. - Paul. On Tue, Apr 17, 2012 at 8:18 PM, Ivan Enderlin @ Hoa < ivan.enderlin@hoa-project.net> wrote: > Hi everyone, > > I have noticed that it is not possible to do something like that: > > // foo.php > return ['foo' =3D> 'bar']; > > // bar.php > var_dump((require 'foo.php')['foo']); > > Array access on a require does not work: we have a parse error. Is it jus= t > a parser issue? Because a file can return an array without any problem. > For now, one possible solution is to write a function that requires a fil= e > and returns the result, such as: > > // bar.php > function my_require ( $file ) { return require $file; } > var_dump(my_require('foo'.php'**)['foo']); > > It would be nice if require (and require_once, include and include_once) > instructions would behave like functions when returning values. > Thoughts? > > In the same way, it is not possible for now to do something like that: > function f ( ) { > return function ( $msg ) { > > return $msg . '!'; > } > } > f()('foo'); > We have a parse error again. Is it a parser issue? > It could be interesting to have this feature in PHP because file can > return closure! It would be great to extend this syntax on require and > others instructions, such as: > > (require 'baz.php')('a message'); // chaining methods calls > > Finally, what about exporting only some symbols? It could be a middle ste= p > between declaring classes as private, protected and public and all public= . > We can imagine somethings like: > > // foo.php > class IAmPrivate { } > class IAmPublic { } > > export [IAmPublic]; // or export [IAmPublic::class], please see current > discussion about Classname::class proposition. > > Here, the =93export=94 keyword will act like =93return=94 but it will spe= cify that > all declaring symbols inside the file will not be exposed outside the fil= e > except specified ones. It could add a =93module aspect=94 to PHP, and it = does > not break the compatibility. > > Thoughts? > > Best regards. > > -- > Ivan Enderlin > Developer of Hoa > http://hoa.42/ or http://hoa-project.net/ > > PhD. student at DISC/Femto-ST (Vesontio) and INRIA (Cassis) > http://lifc.univ-fcomte.fr/ and http://www.inria.fr/ > > Member of HTML and WebApps Working Group of W3C > http://w3.org/ > > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --485b390f7a06eba27304bde4faa4--