Re: [PHP4BETA] Is this a bug? Default params?

From: Date: Mon, 09 Aug 1999 17:37:05 +0000
Subject: Re: [PHP4BETA] Is this a bug? Default params?
References: 1  Groups: php.version4 
Request: Send a blank email to php-version4+get-3244@lists.php.net to get a copy of this message
Samuel Liddicott wrote: > > > -----Original Message----- > > From: georgeh@theta.blowtorch.com [mailto:georgeh@theta.blowtorch.com]On > > Behalf Of George Hartz > > Sent: 09 August 1999 05:38 PM > > To: Samuel Liddicott; php4beta@lists.php.net > > Subject: Re: [PHP4BETA] Is this a bug? Default params? > > > > > Function isAdmin($username = "$login[\"username\"]") { > > > > > > Should it have worked in php3 (it did)? Why doesn't it now? Are only > > > constants allowed as default params??? > > > > I caught that problem when Beta1 first came out. I was told its a > > non-supported feature, not a bug. (ie, its not going to change.) > > > > It was a real headache for me, I used that functionality literally > > hundreds of times on a dozen sites. > > I think it should be a feature, because otherwise we have: > > function isAdmin($username) { > if (! isVar($Username)) { > $UserName=$GLOBALS["login"]["username"]; > } > > everywhere You're right. My guess, however, is that because Zend does a JIT-type precompiling of the file as opposed to the older PHP parser that went line-by-line, you're not able to do that, because the routines that handle functions build all of that statically (ie, you can't set it to a dynamic value, because at the time of compiling, there ISN'T any dynamic values) A better option, given the assumption that it can't be changed, is to add a simple shorthand for it, something like this: $Username ?= $GLOBALS["login"]["username"]; Figuring that "?=" is semi-intuitive for "equals if not set" or something along those lines... Actually, now that I've said that, I really like the idea! :) That's actually useful in a lot of situations, and could probably be coded to execute faster than the if test, followed by a variable assignment. - George -- email:dotorg@bangsplat.org;url:www.bangsplat.org;uin:153182;aim:tgd98 GCS/GP/GS/GFA d- s+: a- C++++$ UL++++$ P+++$ L+++$ E- W++>$ N+@ !o K+++ w--- !O M-@ V PS+ PE Y+ PGP t-(+) 5- X++ R-(--) tv+ b+++ DI++ D++ G+ e* h r y++

« previous php.version4 (#3244) next »