Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:33201 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 22874 invoked by uid 1010); 17 Nov 2007 04:34:10 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 22858 invoked from network); 17 Nov 2007 04:34:10 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Nov 2007 04:34:10 -0000 Authentication-Results: pb1.pair.com smtp.mail=rasmus@lerdorf.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=rasmus@lerdorf.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain lerdorf.com from 204.11.219.139 cause and error) X-PHP-List-Original-Sender: rasmus@lerdorf.com X-Host-Fingerprint: 204.11.219.139 mail.lerdorf.com Received: from [204.11.219.139] ([204.11.219.139:50672] helo=mail.lerdorf.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 05/1B-51194-14F6E374 for ; Fri, 16 Nov 2007 23:34:10 -0500 Received: from trainburn-lm-corp-yahoo-com.local (c-24-6-228-50.hsd1.ca.comcast.net [24.6.228.50]) (authenticated bits=0) by mail.lerdorf.com (8.14.2/8.14.2/Debian-1) with ESMTP id lAH4Y17H026250 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 16 Nov 2007 20:34:03 -0800 Message-ID: <473E6F38.4020008@lerdorf.com> Date: Fri, 16 Nov 2007 20:34:00 -0800 User-Agent: Thunderbird 2.0.0.9 (Macintosh/20071031) MIME-Version: 1.0 To: Sam Barrow CC: Sean Coates , Michael McGlothlin , internals@lists.php.net 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> In-Reply-To: <1195273116.12249.28.camel@sams-room> X-Enigmail-Version: 0.95.5 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: ClamAV 0.91.2/4822/Fri Nov 16 17:26:56 2007 on colo.lerdorf.com X-Virus-Status: Clean Subject: Re: [PHP-DEV] Re: Question about superglobals From: rasmus@lerdorf.com (Rasmus Lerdorf) 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