Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:27919 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 67021 invoked by uid 1010); 8 Feb 2007 17:32:42 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 67006 invoked from network); 8 Feb 2007 17:32:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Feb 2007 17:32:42 -0000 Authentication-Results: pb1.pair.com smtp.mail=guilhermeblanco@hotmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=guilhermeblanco@hotmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain hotmail.com designates 65.54.246.221 as permitted sender) X-PHP-List-Original-Sender: guilhermeblanco@hotmail.com X-Host-Fingerprint: 65.54.246.221 bay0-omc3-s21.bay0.hotmail.com Windows 2000 SP4, XP SP1 Received: from [65.54.246.221] ([65.54.246.221:42530] helo=bay0-omc3-s21.bay0.hotmail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CC/40-00136-8BE5BC54 for ; Thu, 08 Feb 2007 12:32:40 -0500 Received: from BAY126-W23 ([65.55.131.58]) by bay0-omc3-s21.bay0.hotmail.com with Microsoft SMTPSVC(6.0.3790.2668); Thu, 8 Feb 2007 09:32:38 -0800 Message-ID: Content-Type: multipart/alternative; boundary="_21e312b0-b9e4-4a17-b6ad-8c5de375f452_" X-Originating-IP: [200.168.90.70] To: Date: Thu, 8 Feb 2007 20:32:38 +0300 Importance: Normal MIME-Version: 1.0 X-OriginalArrivalTime: 08 Feb 2007 17:32:38.0172 (UTC) FILETIME=[2096BDC0:01C74BA7] Subject: Suggestion: global variables being accessed in local scope From: guilhermeblanco@hotmail.com (Guilherme Blanco) --_21e312b0-b9e4-4a17-b6ad-8c5de375f452_ Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable Hello PHP maintainers,During this week, I spoke with Sara Golemon about the= possibility to change one current behavior of PHP.My first suggestion, as = you can see in my blog post: http://blog.bisna.com/archives/32#comments was= a new function called register_superglobal.While talking with her, I found= that it'll be easier to be implemented another thing.Currently, when we de= al with objects and functions in a PHP application, to access most common v= ariables, 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 Registry::get("DB"); // ...}And finally... = via Factory:function m() { $DB =3D Env::getDatabaseConnection(); // ...= }We can also specify via runkit a superglobal variable (DB), and use it.Whi= le all those solutions have some costs, maybe there is a possibility to cha= nge the structure and simplify all those lines of code.As I already said, m= y first idea was a function, register_superglobal, which you register it an= d access it in a local scope without using none of the examples I listed.Sa= ra told me about superglobals and etc, but I suggested her about the possib= ility to change the idea a little. Here is the comment I describe 2 possibl= e ideas:"The perfect behavior should be (inside a function), if a variable= =0A= does not exist, try to access a global (without doing via $GLOBALS or=0A= global). If it doesn=92t exist in the second try, then throw a fatal=0A= error. With this, you do not need to think in superglobal variable or=0A= anything else. Maybe this suggestion is currently too much difficult to ach= ieve.=0A= The workaround can be done using normal variables. But, as I=0A= mentioned before, when the statement uses a variable, it checks for the=0A= local variables declarations hash table; the idea is different here=85 if= =0A= the variable does not exist in local, look in the hash table I=0A= mentioned (which stores the subscribed variables to behavior like=0A= superglobal) and, if found, grab the variable from the global variable=0A= declarations hash table.=0A= As you can see, there will be only one performance impact (in normal=0A= variable), doing a hash table checking. You do not need to change=0A= autoglobal or static variables. In an average system, the needed time=0A= to do this checking will be an advantage than the currently best=0A= approach (Registry). You lose in one side, but receive more in the=0A= other."She agreed with my idea ("That=92s all doable, and with autoglobals = being CVs now, it=92s even doable=0A= without too much performance impact on the global fetches themselves=85"), = BUT she said I will have to convince engine team to accept this idea too. A= lso, she said that will be a too much added complexity for too little. I di= sagree with her, since currently there are much more processment retrieving= one object from a Registry or using a global accessor than another compile= r hash checking. The performance impact is almost irrelevant (cannot be mea= sured) and the final solution is cleaner than all the others. If you look a= t real world large applications, you can experience these workarounds. And,= as I checked with my contact list (around 600), it'll be a great improveme= nt of PHP.Now I am leaving this suggestion to internals list, and I hope yo= u look affectionately at it.Best 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 _________________________________________________________________ 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= --_21e312b0-b9e4-4a17-b6ad-8c5de375f452_--