Re: [PHP-DEV] wrong implementation of isset()?

2001-02-07 Thread Andi Gutmans

At 03:02 AM 2/7/2001 +0100, Cynic wrote:
with all respect to the people who develop the language, I
think this is nonsense:

$rs = mysql_query( 'select x, y, z from foo where ...' ) ;
$x = mysql_fetch_array( $rs , MYSQL_NUM ) ;
var_dump( $x[2] ) ;
var_dump( isset( $x[2] ) ) ;

NULL # well, the column contains null values
bool(false)

But since (almost) everybody else disagrees, I must be missing
something obvious.

BTW, does $x = null really equal to unset( $x ) or does
isset() just get fooled by its value?

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.
In any case, you can always use the === operator to check if something is 
really NULL and not false.
if ($x === NULL) {
}
I can't remember off hand all the reasons for isset(NULL) being false but 
the main reason is that it makes a lot of sense because what the NULL value 
is supposed to mean is that there's no value. Also it allows us to 
differentiate between functions returning bool(false) and null values. 
Hence also the === operator.
I really think that if your script differentiates between these two cases 
you might not be writing it very well.
OK, I know it's a messy Email. I'm on the way to bed but I hope it 
clarifies a few things :)
Andi


-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DEV] wrong implementation of isset()?

2001-02-06 Thread Martin Jansen

The following was reported today in the german language newsgroup
news:de.comp.lang.php:

?php
$a = NULL;
if (isset($a)) { print "ok, du hast recht"; }
?

Shouldn't this script generate some output? IMO $a is set
and isset() should return true.

The manual says:
"isset -- Determine whether a variable is set"

So following the manual means that there _has_ to be
output because $a is set in fact.

Or am I wrong?

-Martin
--
 Martin Jansen  mailto:[EMAIL PROTECTED]   
 Monschau, Germany  http://martin-jansen.de 


--
PHP Development Mailing List http://www.php.net/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DEV] wrong implementation of isset()?

2001-02-06 Thread Andrei Zmievski

On Tue, 06 Feb 2001, Martin Jansen wrote:
 The following was reported today in the german language newsgroup
 news:de.comp.lang.php:
 
 ?php
 $a = NULL;
 if (isset($a)) { print "ok, du hast recht"; }
 ?
 
 Shouldn't this script generate some output? IMO $a is set
 and isset() should return true.
 
 The manual says:
 "isset -- Determine whether a variable is set"
 
 So following the manual means that there _has_ to be
 output because $a is set in fact.
 
 Or am I wrong?

NULL == not set

-Andrei

Some people try to achieve immortality through their work, others
through their children. I hope to achieve immortality by not dying.
-- Woody Allen

-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DEV] wrong implementation of isset()?

2001-02-06 Thread Bjoern Hoehrmann

* Andrei Zmievski wrote:
 ?php
 $a = NULL;
 if (isset($a)) { print "ok, du hast recht"; }
 ?
 
 Shouldn't this script generate some output? IMO $a is set
 and isset() should return true.

NULL == not set

Great analysis. What about answering the question? Stanislav Malyshev
said some months ago this is 'strange', see the discussion around bug
6076. Tell us at least, why this actually isn't strange.
-- 
Bjrn Hhrmann ^ mailto:[EMAIL PROTECTED] ^ http://www.bjoernsworld.de
am Badedeich 7  Telefon: +49(0)4667/981028  http://bjoern.hoehrmann.de
25899 Dagebll # PGP Pub. KeyID: 0xA4357E78 # http://learn.to/quote [!]e
~~ will code for food. ~~   

-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DEV] wrong implementation of isset()?

2001-02-06 Thread Andrei Zmievski

On Tue, 06 Feb 2001, Bjoern Hoehrmann wrote:
 NULL == not set
 
 Great analysis. What about answering the question? Stanislav Malyshev
 said some months ago this is 'strange', see the discussion around bug
 6076. Tell us at least, why this actually isn't strange.

By default, any unset variable has value NULL - and isset(NULL) returns
false to indicate that. Similarly, assigning NULL to a variable unsets
it.

-Andrei
* The great thing about standards is that there are so many to choose from. *

-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DEV] wrong implementation of isset()?

2001-02-06 Thread Martin Jansen

On Tue, 6 Feb 2001 13:43:29 -0600, Andrei Zmievski wrote:
On Tue, 06 Feb 2001, Bjoern Hoehrmann wrote:
 NULL == not set
 
 Great analysis. What about answering the question? Stanislav Malyshev
 said some months ago this is 'strange', see the discussion around bug
 6076. Tell us at least, why this actually isn't strange.

By default, any unset variable has value NULL - and isset(NULL) returns
false to indicate that. Similarly, assigning NULL to a variable unsets
it.

But if I declare the variable in my script (and in the namespace),
it's existing, no matter which value it has (String, Integer, NULL
or whatever). As a result of that, isset() should return true.

-Martin


-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP-DEV] wrong implementation of isset()?

2001-02-06 Thread Chris Newbill

null, adjective: having no value

IMHO, isset() should be left as is.  Either way if you are looking for a
null value you will have to use '== NULL' or is_null().

if (isset($a)  is_null($a))

if (isset($a))
if (is_null($a))

etc...

The only possible situation I can think(right now) of where this might be
useful is if you do not care that the value is null and null is a perfectly
legal value(or non-value).  In which case, all you are accomplishing is
breaking everyone else's script who does not allow null values because they
rely on isset() returning false and not letting these by.

Chris

-Original Message-
From: Martin Jansen [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, February 06, 2001 2:19 PM
To: Andrei Zmievski; Bjoern Hoehrmann
Cc: PHP Development Mailing List
Subject: Re: [PHP-DEV] wrong implementation of isset()?


On Tue, 6 Feb 2001 13:43:29 -0600, Andrei Zmievski wrote:
On Tue, 06 Feb 2001, Bjoern Hoehrmann wrote:
 NULL == not set

 Great analysis. What about answering the question? Stanislav Malyshev
 said some months ago this is 'strange', see the discussion around bug
 6076. Tell us at least, why this actually isn't strange.

By default, any unset variable has value NULL - and isset(NULL) returns
false to indicate that. Similarly, assigning NULL to a variable unsets
it.

But if I declare the variable in my script (and in the namespace),
it's existing, no matter which value it has (String, Integer, NULL
or whatever). As a result of that, isset() should return true.

-Martin


--
PHP Development Mailing List http://www.php.net/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DEV] wrong implementation of isset()?

2001-02-06 Thread Ron Chmara

"Mark J. Hershenson" wrote:
  Great analysis. What about answering the question? Stanislav Malyshev
  said some months ago this is 'strange', see the discussion around bug
  6076. Tell us at least, why this actually isn't strange.
  By default, any unset variable has value NULL - and isset(NULL) returns
  false to indicate that. Similarly, assigning NULL to a variable unsets
  it.
  -Andrei
  * The great thing about standards is that there are so many to choose from. *
 Well, sure, isset(NULL) should return false, it's not a variable set in the
 scope. A constant(?) yes, but not a variable.
 
 But if you set a variable at some point in a script, would it not stand to
 reason that that name is in the global/local namespace, and therefore IS
 set?

Perhaps, in order to maintain compatibility, we should re-document is_set,
create the documentation for is_null, and look into creating a new function
that will determine if something has "ever been inside the namespace", regardless
of its current value, or absence of value.

Right now, the *documentation* for isset does imply that:
$a = NULL;
isset($a); //TRUE
when this is not the case. 

Specifically, the documentation says "Returns true if a variable exists"
rather than "Returns true if a variable exists, but has not been sunsequently
assigned a value (or non-value) of NULL, and has not been unset().

-Ronabop

--
Personal:  [EMAIL PROTECTED], 520-326-6109, http://www.opus1.com/ron/
Work: [EMAIL PROTECTED], 520-546-8993, http://www.pnsinc.com/
The opinions expressed in this email are not neccesarrily those of myself,
my  employers, or any of the other little voices in my head.

-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DEV] wrong implementation of isset()?

2001-02-06 Thread John Donagher

On Wed, 7 Feb 2001, [ISO-8859-1] André Langhorst wrote:

 we should just define (and document) this similar to Andrei (note, I do 
 not use the word "the same" I use that word equal, what means different 
 things):
 
 NULL  equals  absence_of_value  equals  absence_of_variable_in_namespace
 
 I can imagine no case where people would need to differentiate between 
 NULL and never been in namespace, we should not allow this, otherwise we 
 would introduce the differentiation into a third state, non existent, 
 what raises the wtf-factor and is not required as far as I can think
 
 andré
 

I agree. I've watched a lot of seasoned programmers learning PHP and the
behaviour of various functions operating on NULL, 0, and '' has always had an
extremely high wtf-factor (I really like that term). Most of the former
discrepancies have been fixed, though.

Try as I might, I can't think of a good case where you'd want to check for NULL
and existance in the namespace.  

-- 

John Donagher
Application Engineer
Intacct Corp. - Powerful Accounting on the Web
408-395-0989
720 University Ave.
Los Gatos CA 95032
www.intacct.com

Public key available off http://www.keyserver.net
Key fingerprint = 4024 DF50 56EE 19A3 258A  D628 22DE AD56 EEBE 8DDD


--
PHP Development Mailing List http://www.php.net/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DEV] wrong implementation of isset()?

2001-02-06 Thread Ron Chmara

Andr Langhorst wrote:
  Perhaps, in order to maintain compatibility, we should re-document is_set,
  create the documentation for is_null, and look into creating a new function
  that will determine if something has "ever been inside the namespace", regardless
  of its current value, or absence of value.
 we should just define (and document) this similar to Andrei (note, I do
 not use the word "the same" I use that word equal, what means different
 things):
 NULL  equals  absence_of_value  equals  absence_of_variable_in_namespace
 I can imagine no case where people would need to differentiate between
 NULL and never been in namespace

(Disclaimer: I think much of this is a bit silly, as it all can be
worked around, or people can avoid using NULL... but for the sake of
those who believe "NULL" should be a value)

Here's a possible case for this:
You have three forms. Each uses differently named variables.
All three post to the same page. One way a user might try to code
for this is:
if (isset($HTTP_POST_VARS[var_only_from_form_one]){ include ("foo");}
if (isset($HTTP_POST_VARS[var_only_from_form_two]){ include ("bar");}

Or using "has_ever-been_a_var" to do the same thing. Now, if one of those var's
has been assigned NULL somehow, their logic breaks, even though the var is
actually there, and has been set with something they consider a "value".

In a more interesting fashion, it adds a possible security feature,
where folks could actually error out their scripts if a user tried
to _introduce_ a faked variable, because it wasn't "supposed to be
there" under the current conditions, or at all. By walking the var arrays,
and checking against the expected vars, a user could send a security
warning if sombody was hacking a URL or faking a form the obvious
case I can think of is folks adding "debug=1" somehow.

-Ronabop

--
Personal:  [EMAIL PROTECTED], 520-326-6109, http://www.opus1.com/ron/
Work: [EMAIL PROTECTED], 520-546-8993, http://www.pnsinc.com/
The opinions expressed in this email are not necessarily those of myself,
my employers, or any of the other little voices in my head.

-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]