Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:27931 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 84851 invoked by uid 1010); 9 Feb 2007 01:03:02 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 84836 invoked from network); 9 Feb 2007 01:03:01 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Feb 2007 01:03:01 -0000 Authentication-Results: pb1.pair.com header.from=guilhermeblanco@hotmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=guilhermeblanco@hotmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain hotmail.com designates 65.54.246.210 as permitted sender) X-PHP-List-Original-Sender: guilhermeblanco@hotmail.com X-Host-Fingerprint: 65.54.246.210 bay0-omc3-s10.bay0.hotmail.com Windows 2000 SP4, XP SP1 Received: from [65.54.246.210] ([65.54.246.210:58592] helo=BAY0-OMC3-S10.bay0.hotmail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F5/E0-11345-448CBC54 for ; Thu, 08 Feb 2007 20:03:00 -0500 Received: from BAY126-W17 ([65.55.131.52]) by BAY0-OMC3-S10.bay0.hotmail.com with Microsoft SMTPSVC(6.0.3790.2668); Thu, 8 Feb 2007 17:02:57 -0800 Message-ID: Content-Type: multipart/alternative; boundary="_a11e5699-f669-4b44-b8c0-83a127c90f31_" X-Originating-IP: [200.168.90.70] To: Date: Fri, 9 Feb 2007 04:02:57 +0300 Importance: Normal MIME-Version: 1.0 X-OriginalArrivalTime: 09 Feb 2007 01:02:57.0909 (UTC) FILETIME=[099B6A50:01C74BE6] Subject: RE: [PHP-DEV] Suggestion: global variables being accessed in local scope From: guilhermeblanco@hotmail.com (Guilherme Blanco) --_a11e5699-f669-4b44-b8c0-83a127c90f31_ Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable Brian,I am sorry about the message indentation... Seems PHP-Internals list = does not like M$ Live(r) Mail! roflI wrote it carefully indented... =3D\I= =0A= read your extension messages, but you idea was different from mine.=0A= What you suggested in that post is exactly what runkit does today.My=0A= idea is a little bit different. If possible, the idea is something like=0A= this (sorry, but my C skill are not so good and I'll write in Java):I extra= cted the source from a Krakatoa compiler I wrote (Krakatoa =3D> C)...Curren= tly, PHP tries to access a local variable usage/assignment with this (Compi= ler class scope):// Retrieve variable from local scopeVariable v =3D (Varia= ble ) this.symbolTable.getInLocal( this.lexer.getStringValue() );if ( v =3D= =3D null ) { // Variable does not exist in local scope, throw a fatal er= ror. this.error.show("FATAL ERROR: Undefined Variable " + this.lexer.get= StringValue(), CompilerError.FATAL_ERROR);}The best approach that I suggest= ed eliminates the need of global keyword and also the $GLOBALS autoglobal a= rray.The source code I have to do what I suggest is this:// Retrieve variab= le from local scope=0A= Variable v =3D (Variable ) this.symbolTable.getInLocal( this.lexer.getStrin= gValue() );=0A= =0A= if ( v =3D=3D null ) { // Try to retrieve the variable from global scope= v =3D (Variable ) this.symbolTable.getInGlobal( this.lexer.getStringVal= ue() ); if ( v =3D=3D null ) { // Variable does not exist in = local nor in global scope, throw a fatal error.=0A= this.error.show("FATAL ERROR: Undefined Variable " + this.lexer.get= StringValue(), CompilerError.FATAL_ERROR); }=0A= }As=0A= you can see, the only change needed is in a throw-able error (Undefined=0A= variable), which does a second look-up in the symbolTable.Doing=0A= this, you do not need to use $GLOBALS nevermore! And also, global can=0A= be extinct too, since the compiler recognizes the variable in global=0A= scope alone.I know the PHP source is not well commented and=0A= structured, but I think this is not an impossible change to be done,=0A= and will bring a lot of benefits to all PHP developers.I wish God come here= and make my message indented until it reaches the PHP-Internals list.... = =3DDBest regards,Guilherme Blanco - Web Developer=0A= CBC - Certified Bindows Consultant=0A= Cell Phone: +55 (16) 9166-6902=0A= URL: http://blog.bisna.com=0A= MSN: guilhermeblanco@hotmail.com=0A= S=E3o Carlos - SP/Brazil> Date: Thu, 8 Feb 2007 12:07:23 -0600> From: brian= m@dealnews.com> To: guilhermeblanco@hotmail.com> CC: internals@lists.php.ne= t> Subject: Re: [PHP-DEV] Suggestion: global variables being accessed in lo= cal scope> > Well, this was a little hard to read, but, let me see if I und= erstand > one thing. You would have PHP look in the local scope and then a= lso in > the global scope? If so, I would never support that idea. I reme= mber > an email from Rasmus about why PHP's scoping is the way it is. > Som= ething to do with chasing down a scope issue in a C app for days.> > I wrot= e an extension to do this about 4 years ago. I submitted it to > the, then= pear-dev list.> > http://marc.theaimsgroup.com/?l=3Dpear-dev&m=3D104534556= 711383&w=3D2> > It was not received well, so I did not pursue it. To see a= ll the > replies look at > http://marc.theaimsgroup.com/?l=3Dpear-dev&w=3D2= &r=3D48&s=3DNew+PHP+extension&q=3Db > and read the ones titled "New PHP Ext= ension". MARC did not thread the > discussion well.> > My extension did no= t have a function, but required php.ini settings to > declare the variable = names. It also required they start with and under > score if I remember co= rrectly.> > Now the bad news. The code was lost in a hard drive crash. I = am not > sure it would work now though. I am sure a lot has changed in 4 y= ears.> > > Guilherme Blanco wrote:> > Hello PHP maintainers,During this wee= k, I spoke with Sara Golemon about the possibility to change one current be= havior of PHP.My first suggestion, as you can see in my blog post: http://b= log.bisna.com/archives/32#comments was a new function called register_super= global.While talking with her, I found that it'll be easier to be implement= ed another thing.Currently, when we deal with objects and functions in a PH= P application, to access most common variables, we have to do one of these = things:function m() { global $DB; // ...}Another one:function m() { $= DB =3D Database::getInstance(); // ...}Or:function m() { $DB =3D Regist= ry::get("DB"); // ...}And finally... via Factory:function m() { $DB =3D= Env::getDatabaseConnection(); // ...}We can also specify via runkit a sup= erglobal variable (DB), and use it.While all those solutions have some cost= s, maybe there is a possibility to change the structure and simplify all th= ose lines of code.As I already said, my first idea was a > function, regist= er_superglobal, which you register it and access it in a local scope withou= t using none of the examples I listed.Sara told me about superglobals and e= tc, but I suggested her about the possibility to change the idea a little. = Here is the comment I describe 2 possible ideas:"The perfect behavior shoul= d be (inside a function), if a variable> > does not exist, try to access a = global (without doing via $GLOBALS or> > global). If it doesn=92t exist in = the second try, then throw a fatal> > error. With this, you do not need to = think in superglobal variable or> > anything else. Maybe this suggestion is= currently too much difficult to achieve.> > The workaround can be done usi= ng normal variables. But, as I> > mentioned before, when the statement uses= a variable, it checks for the> > local variables declarations hash table; = the idea is different here=85 if> > the variable does not exist in local, l= ook in the hash table I> > mentioned (which stores the subscribed variables= to behavior like> > superglobal) and, if found, grab the variable from the= global variable> > declarations hash table.> > As you can see, there will = be only one performance impact (in normal> > variable), doing a hash table = checking. You do not need to change> > autoglobal or static variables. In a= n average system, the needed time> > to do this checking will be an advanta= ge than the currently best> > approach (Registry). You lose in one side, bu= t receive more in the> > other."She agreed with my idea ("That=92s all doab= le, and with autoglobals being CVs now, it=92s even doable> > without too m= uch performance impact on the global fetches themselves=85"), BUT she said = I will have to convince engine team to accept this idea too. Also, she said= that will be a too much added complexity for too little. I disagree with h= er, since currently there are much more processment retrieving one object f= rom a Registry or using a global accessor than another compiler hash checki= ng. The performance impact is almost irrelevant (cannot be measured) and th= e final solution is cleaner than all the others. If you look at real world = large applications, you can experience these workarounds. And, as I checked= with my contact list (around 600), it'll be a great improvement of PHP.Now= I am leaving this suggestion to internals list, and I hope you look affect= ionately at it.Best regards,Guilherme Blanco - Web Developer> > CBC - Certi= fied Bindows Consultant> > Cell Phone: +55 (16) 9166-6902> > URL: http://bl= og.bisna.com> > MSN: guilhermeblanco@hotmail.com> > S=E3o Carlos - SP/Brazi= l> > _________________________________________________________________> > O= Windows Live Spaces est=E1 aqui! Descubra como =E9 f=E1cil criar seu espa= =E7o na Web e sua rede amigos.> > http://spaces.live.com/signup.aspx> > -- = > > Brian Moon> -------------> http://dealnews.com/> It's good to be cheap = =3D)> > -- > PHP Internals - PHP Runtime Development Mailing List> To unsub= scribe, visit: http://www.php.net/unsub.php>=20 _________________________________________________________________ Ligue para os seus amigos gr=E1tis. Fa=E7a chamadas de PC-para-PC pelo mess= enger-- GR=C1TIS http://get.live.com/messenger/overview= --_a11e5699-f669-4b44-b8c0-83a127c90f31_--