Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:33202 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 24926 invoked by uid 1010); 17 Nov 2007 04:39:53 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 24911 invoked from network); 17 Nov 2007 04:39:53 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Nov 2007 04:39:53 -0000 Authentication-Results: pb1.pair.com smtp.mail=sam@sambarrow.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=sam@sambarrow.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain sambarrow.com from 205.234.132.11 cause and error) X-PHP-List-Original-Sender: sam@sambarrow.com X-Host-Fingerprint: 205.234.132.11 scottsdale.servershost.net Received: from [205.234.132.11] ([205.234.132.11:38659] helo=scottsdale.servershost.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4E/5B-51194-9907E374 for ; Fri, 16 Nov 2007 23:39:53 -0500 Received: from [216.15.51.211] (port=50266 helo=[192.168.1.90]) by scottsdale.servershost.net with esmtpsa (SSLv3:RC4-MD5:128) (Exim 4.68) (envelope-from ) id 1ItFTF-0003nQ-Ml; Fri, 16 Nov 2007 22:39:53 -0600 To: Rasmus Lerdorf Cc: Sean Coates , Michael McGlothlin , internals@lists.php.net In-Reply-To: <473E6F38.4020008@lerdorf.com> References: <8D.46.01128.768AD374@pb1.pair.com> <1195246391.21084.15.camel@sbarrow-desktop> <1195250285.4012.6.camel@johannes.nop> <1195251014.21084.20.camel@sbarrow-desktop> <473E349E.3050704@swplumb.com> <1195259494.10547.2.camel@sams-room> <0E6C7DB2-4126-4660-A813-E21C03045247@caedmon.net> <473E5F4F.2020508@swplumb.com> <6743D10C-4AE9-4974-B0C3-3A632A0326F1@caedmon.net> <1195273116.12249.28.camel@sams-room> <473E6F38.4020008@lerdorf.com> Content-Type: text/plain Date: Fri, 16 Nov 2007 23:39:54 -0500 Message-ID: <1195274394.12249.34.camel@sams-room> Mime-Version: 1.0 X-Mailer: Evolution 2.10.1 Content-Transfer-Encoding: 7bit X-Antivirus-Scanner: Clean mail though you should still use an Antivirus X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - scottsdale.servershost.net X-AntiAbuse: Original Domain - lists.php.net X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - sambarrow.com X-Source: X-Source-Args: X-Source-Dir: Subject: Re: [PHP-DEV] Re: Question about superglobals From: sam@sambarrow.com (Sam Barrow) 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 >