Derick Rethans wrote:
On Mon, 18 Aug 2003, Griggs Domler wrote:


have come to the conclusion that a
language statement, such as isset(), would be the best option.


If you search the archives, you would have noticed that this was brought up before, and shot down.

Derick


Ok, I have spent hours searching the archives and bugs database, and have come up with the following threads. I added a summarizing comment below each one.

Notice that the only one that matches the default value request is the last one, which
represents an OPEN item in the bugs database. :-)  (And I added a comment to that 
entry.)

P.S. I think calling the new construct default() is better than getd().



****** Ternary operator enhancement for fluent code
http://marc.theaimsgroup.com/?t=96220168300004&r=1&w=2
Andi: "Personally I don't want to add too many "weird" constructs to PHP. I think
they reduce readability and go against one of the strengths of PHP which is
an easy language for anyone with a C/Perl/Java background. These constructs
are really cryptic."

NOTE: a new language construct such as default() is not cryptic.



****** wrong implementation of isset()?
http://marc.theaimsgroup.com/?l=php-dev&m=98148190704386&w=2
Andi: "unset() removes it from the symbol table and $x = NULL; changes it to be a
NULL value. As far as PHP scripts are concerned it's pretty much the same
thing. There are certain situations where you can't really nuke the
variable but you want to mark it as dead."

NOTE: a new language construct such as default() would not require changing isset()



****** builtin functions / constructs
http://marc.theaimsgroup.com/?l=php-dev&m=98536452122073&w=2
Zeev: "There aren't too many built-in constructs that behave exactly like functions,
as a matter of fact, I don't think there are any.  The ones that come close:
isset() and empty() - their different semantics is that they won't
display a warning when fed a non existent argument (regardless of error
reporting)..."

NOTE: a new language construct such as default() would use semantics like this



****** variable_exists() patch
http://marc.theaimsgroup.com/?l=php-dev&m=106081362832056&w=2
Zeev: "Don't use nulls as values and you won't have to use hacks.  null is not a
value, was never meant to be a value, and won't be a value."

NOTE: a new language construct such as default() would not use nulls as values



****** userland macros
http://marc.theaimsgroup.com/?l=php-dev&m=106123302908576&w=2
Timm: "use cc -E to do your own macros"

NOTE: a new language construct such as default() would not require separate preprocessing



****** PROPOSAL: default value handling
http://marc.theaimsgroup.com/?l=php-dev&m=104226313312160&w=2
Andi: "boolean operators must return true or false"

NOTE: a new language construct such as default() is not a boolean operator



****** Requesting a nicer way of setting undefined variables to a default value.
http://bugs.php.net/bug.php?id=24949
[OPEN]

NOTE: a new language construct such as default() would provide this requested feature



In conclusion,

I could not find anywhere that this requested feature was shot down.

Since it cannot be implemented reliably or effectively in userland,
users stand to benefit from having this simple and commonly used feature
incorporated into a language-level construct.

At the same time, it is clearly a feature request/enhancement.


The default() construct seems even more useful than either empty() or isset().


In web forms, a text field left blank is automatically given
the value of an empty string, but forms validators must treat that
as being 'not set'. So isset() is not enough for that check, since it would count
the empty string as being set, which it is from a variable point of view. And empty()
treats "0" as not set, so that is not enough if you need to allow submitting
a zero in a form.

  if (default($_POST['qty'],"")!="") { }
  // vs
  if (isset($_POST['qty']) && $_POST['qty']!="") { }
  // vs
  if (!empty($_POST['qty']) || (isset($_POST['qty']) && $_POST['qty']=="0")) { }



So, did I miss something in the archives where this was requested and shot down?


Either way, thanks for your time, and for helping to make PHP what it is today.



Guy N. Hurst





-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to