Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:33204 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 37256 invoked by uid 1010); 17 Nov 2007 05:54:21 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 37241 invoked from network); 17 Nov 2007 05:54:20 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Nov 2007 05:54:20 -0000 Authentication-Results: pb1.pair.com smtp.mail=larry@garfieldtech.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=larry@garfieldtech.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain garfieldtech.com from 76.96.30.16 cause and error) X-PHP-List-Original-Sender: larry@garfieldtech.com X-Host-Fingerprint: 76.96.30.16 qmta01.emeryville.ca.mail.comcast.net Received: from [76.96.30.16] ([76.96.30.16:34115] helo=QMTA01.emeryville.ca.mail.comcast.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 67/FC-51194-A028E374 for ; Sat, 17 Nov 2007 00:54:20 -0500 Received: from OMTA14.emeryville.ca.mail.comcast.net ([76.96.30.60]) by QMTA01.emeryville.ca.mail.comcast.net with comcast id Dgmh1Y0051HpZEs0A02t00; Sat, 17 Nov 2007 05:54:19 +0000 Received: from earth.ufp ([71.228.13.89]) by OMTA14.emeryville.ca.mail.comcast.net with comcast id DhuJ1Y0071vH2xB0800000; Sat, 17 Nov 2007 05:54:19 +0000 X-Authority-Analysis: v=1.0 c=1 a=tJZsWP4XKNgA:10 a=BFXKlz3ntVo8cQPJkGUA:9 a=BF31BaIcc10UEe12P14A:7 a=Mv9UzPYhxIRmzmgc4z98xVrDryIA:4 a=FHBbIDN7CdwA:10 a=9XSpoOj3B7kA:10 Received: from localhost (localhost [127.0.0.1]) by earth.ufp (Postfix) with ESMTP id 5D28AD8307 for ; Fri, 16 Nov 2007 23:54:15 -0600 (CST) Received: from earth.ufp ([127.0.0.1]) by localhost (earth.ufp [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id F+l-XNA5iAE8 for ; Fri, 16 Nov 2007 23:54:15 -0600 (CST) Received: from vulcan.ufp (vulcan.ufp [192.168.42.4]) by earth.ufp (Postfix) with ESMTP id 381CDD8303 for ; Fri, 16 Nov 2007 23:54:05 -0600 (CST) To: internals@lists.php.net Date: Fri, 16 Nov 2007 23:54:34 -0600 User-Agent: KMail/1.9.6 (enterprise 0.20070907.709405) References: <8D.46.01128.768AD374@pb1.pair.com> <473E6F38.4020008@lerdorf.com> <1195274394.12249.34.camel@sams-room> In-Reply-To: <1195274394.12249.34.camel@sams-room> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-ID: <200711162354.34489.larry@garfieldtech.com> Subject: Re: [PHP-DEV] Re: Question about superglobals From: larry@garfieldtech.com (Larry Garfield) As a predecessor of mine at work devised not one but two systems that used global variables as their primary means of internal communication, and I got to sit next to the guy who had to debug and maintain both of them for a year before finally going insane and quitting, I have to agree with Rasmus. Typing "global" isn't just an extra six characters. It's being polite to the people who will have to maintain your code after you're gone. Undeclared globals are a form of extreme sadism, no matter how much documentation you think you've provided. Declared globals are merely ordinary, run-of-the-mill sadism. :-) I don't see a benefit in the first place. Singletons, collector functions, or as a last resort the global keyword are all viable alternatives. Leave extra superglobals to runkit where such weird edge cases belong. On Friday 16 November 2007, Sam Barrow wrote: > I disagree, although you do have a very good point. But simple logic > flaws can cause huge bugs regardless, whether it would be because of a > superglobal or any other programmer error. Although you have a point, > the only place where we disagree is that I think the benefits outweigh > the risks. > > On Fri, 2007-11-16 at 20:34 -0800, Rasmus Lerdorf wrote: > > Sam Barrow wrote: > > > You say that superglobals were not designed to be user defined, think > > > about it, the concept of a superglobal is present in C and C++, two of > > > the maturest and strictest languages around. > > > > The concept of having to declare your globals is unique to PHP, true. > > It is one of the oldest features in PHP too. So, a little history... > > > > Back in 1989 I spent at least a month chasing a bug at a company in > > Canada called Bell Northern Research. It was a weird crash bug in a > > rather complicated system. It was mostly written in C and after pouring > > through reams and reams of code printouts day after day, I finally found > > that it was due to a side effect of some obscure function overwriting a > > global variable that was used in a completely different area of the > > code. That particular feature of the C language was not popular with me > > for a long time after that, and when it came time to work out function > > scoping of variables in PHP, I made sure to not make that same mistake. > > > > And yes, because PHP is a web language and there are common aspects of a > > web request that many functions will need to act on, it makes sense to > > have a finite number of clearly labeled global arrays like _GET, _POST, > > etc. And later on, being able to access any global via $_GLOBALS was > > added, but again, it is a very descriptive name and not likely to result > > in someone mistaking it for something else and ending up with strange > > side effects. > > > > I am definitely not in favor of destroying what I consider a rather good > > design decision just to avoid a couple of keystrokes here and there. So > > yes, you will have to keep adding "global $cfg;" to your functions, or > > accessing it via $_GLOBALS['cfg'], and when you forget, it won't work. > > And yes, you will grumble a bit at that, but that is nothing compared to > > trying to find a bug caused by a global side effect in someone else's > > code. Trust me, you will grumble a lot more at that. > > > > -Rasmus -- Larry Garfield AIM: LOLG42 larry@garfieldtech.com ICQ: 6817012 "If nature has made any one thing less susceptible than all others of exclusive property, it is the action of the thinking power called an idea, which an individual may exclusively possess as long as he keeps it to himself; but the moment it is divulged, it forces itself into the possession of every one, and the receiver cannot dispossess himself of it." -- Thomas Jefferson