Brain Death - functions classes
6 answers - 2338 bytes -

Rob,
I'd go along with the setting a var to null issue (in the cases I have worked so far on, there has not been a need to set variables to null). However, what is wrong with is_null()?
From the php manual chm:
(PHP 4 >= 4.0.4, PHP 5)
is_null -- Finds whether a variable is NULL
Description
bool is_null ( mixed var )
Finds whether the given variable is NULL.
Parameters
var
The variable being evaluated.
Return Values
Returns TRUE if var is null, FALSE otherwise.
<<<<<
And to be very pedantic - as null does not have a type then actually 'x null' should evaluate to absurdity, but PHP is more pragmatic than that ;-)
Cheers - AJ
Alexander J Turner Ph.D.
www.deployview.com
www.nerds-central.blogspot.com
www.project-network.com
Message
From: Robert Cummings [mailto:robert (AT) interjinn (DOT) com]
Sent: 26 August 2006 16:42
To: Alex Turner
Cc: php-general (AT) lists (DOT) php.net
Subject: Re: [PHP] Brain Death - [PHP] functions classes
Sat, 2006-08-26 at 12:49 +0100, Alex Turner wrote:
I don't know what I was on when I wrote the previous post!
In php you cannot create static class variables in this way (doh) or at
least I never have managed. So when faced the this problem I replace
what in C++ would be a class variable with a class function
comme ca:
class MyClass
{
function MyVar($val = null)
{
static $datum;
if(is_null($val))
{
return $datum;
}
$dataum=$val;
}
}
I definitely need more coffee!
Talking about coffee your above code could use some. Try this:
<?php
class MyClass
{
function MyVar( $val=null )
{
static $datum;
if( $val null )
{
return $datum;
}
$datum = $val;
}
}
?>
But also I'd recommend fixing the the problem whereby you
can't set $datum to the null value, otherwise you may run
into unexpected issues down the road.
<?php
class MyClass
{
function MyVar( $val=null, $set=false )
{
static $datum;
if( $set false )
{
return $datum;
}
$datum = $val;
}
}
?>
Cheers,
Rob.
No.1 | | 658 bytes |
| 
At 4:51 PM +0100 8/26/06, Alex Turner wrote:
>And to be very pedantic - as null does not have a type then actually
>'x null' should evaluate to absurdity, but PHP is more pragmatic
>than that ;-)
That's a very good point.
While one NULL variable in php can be compared to another NULL
variable and produce true, it's not so in MySQL.
In MySQL NULL does not equal NULL -- such comparisons produces NULL
and not true. Instead you have to use IS_NULL or NT NULL to check
for NULL.
So, it's probably best to get into the habit of using is_null.
tedd
No.2 | | 1124 bytes |
| 
Sat, 2006-08-26 at 12:41 -0400, tedd wrote:
At 4:51 PM +0100 8/26/06, Alex Turner wrote:
>And to be very pedantic - as null does not have a type then actually
>'x null' should evaluate to absurdity, but PHP is more pragmatic
>than that ;-)
That's a very good point.
While one NULL variable in php can be compared to another NULL
variable and produce true, it's not so in MySQL.
In MySQL NULL does not equal NULL -- such comparisons produces NULL
and not true. Instead you have to use IS_NULL or NT NULL to check
for NULL.
So, it's probably best to get into the habit of using is_null.
I strongly disagree If I'm writing SQL then I adhere to the language
constructs of SQL, if I'm coding in PHP then I adhere to the language
constructs of PHP. There is no reason why one should forgo better
constructs just because they don't appear in other languages. When in
Rome btw, PHP draws strongly from C, and in C NULL == NULL, and
last I checked C predates SQL.
Cheers,
Rob.
No.3 | | 2095 bytes |
| 
At 2:30 PM -0400 8/26/06, Robert Cummings wrote:
Sat, 2006-08-26 at 12:41 -0400, tedd wrote:
At 4:51 PM +0100 8/26/06, Alex Turner wrote:
>>And to be very pedantic - as null does not have a type then actually
>'x null' should evaluate to absurdity, but PHP is more pragmatic
>>than that ;-)
>>
>That's a very good point.
>>
>While one NULL variable in php can be compared to another NULL
>variable and produce true, it's not so in MySQL.
>>
>In MySQL NULL does not equal NULL -- such comparisons produces NULL
>and not true. Instead you have to use IS_NULL or NT NULL to check
>for NULL.
>>
>So, it's probably best to get into the habit of using is_null.
>
>I strongly disagree If I'm writing SQL then I adhere to the language
>constructs of SQL, if I'm coding in PHP then I adhere to the language
>constructs of PHP. There is no reason why one should forgo better
>constructs just because they don't appear in other languages. When in
>Rome btw, PHP draws strongly from C, and in C NULL == NULL, and
>last I checked C predates SQL.
>
>Cheers,
>Rob.
Rob:
As the old woman who kissed the cow said "To each their own."
My reasoning is simple and I don't strongly agree, or disagree, with
other methodologies. I write in several languages, such as php, js,
mySQL, css, and others -- and each have their own constructs. As
such, I try to use similar constructs where ever possible. My memory
isn't what it used to be.
Besides, what Alex Turner said about NULL is correct -- it's absurd
to have NULL evaluate to anything. Just because one language allows
absurdity doesn't mean you have to practice it.
Your mileage may differ and that's :-)
tedd
No.4 | | 2436 bytes |
| 
Sat, 2006-08-26 at 14:23 -0400, tedd wrote:
At 2:30 PM -0400 8/26/06, Robert Cummings wrote:
Sat, 2006-08-26 at 12:41 -0400, tedd wrote:
At 4:51 PM +0100 8/26/06, Alex Turner wrote:
>>And to be very pedantic - as null does not have a type then actually
>'x null' should evaluate to absurdity, but PHP is more pragmatic
>>than that ;-)
>>
>That's a very good point.
>>
>While one NULL variable in php can be compared to another NULL
>variable and produce true, it's not so in MySQL.
>>
>In MySQL NULL does not equal NULL -- such comparisons produces NULL
>and not true. Instead you have to use IS_NULL or NT NULL to check
>for NULL.
>>
>So, it's probably best to get into the habit of using is_null.
>
>I strongly disagree If I'm writing SQL then I adhere to the language
>constructs of SQL, if I'm coding in PHP then I adhere to the language
>constructs of PHP. There is no reason why one should forgo better
>constructs just because they don't appear in other languages. When in
>Rome btw, PHP draws strongly from C, and in C NULL == NULL, and
>last I checked C predates SQL.
>
>Cheers,
>Rob.
Rob:
As the old woman who kissed the cow said "To each their own."
My reasoning is simple and I don't strongly agree, or disagree, with
other methodologies. I write in several languages, such as php, js,
mySQL, css, and others -- and each have their own constructs. As
such, I try to use similar constructs where ever possible. My memory
isn't what it used to be.
Besides, what Alex Turner said about NULL is correct -- it's absurd
to have NULL evaluate to anything. Just because one language allows
absurdity doesn't mean you have to practice it.
language? I know for certain that PHP, C, PERL, and JavaScript all
return true for comparisons of null to itself. I know quite a few
languages too though I'm not sure why you threw CSS in there since
the concept of null doesn't apply.
Your mileage may differ and that's :-)
As always :)
Cheers,
Rob.
No.5 | | 1248 bytes |
| 
Sat, 2006-08-26 at 15:38 -0400, tedd wrote:
At 3:04 PM -0400 8/26/06, Robert Cummings wrote:
Sat, 2006-08-26 at 14:23 -0400, tedd wrote:
Besides, what Alex Turner said about NULL is correct -- it's absurd
>to have NULL evaluate to anything. Just because one language allows
>absurdity doesn't mean you have to practice it.
>
language? I know for certain that PHP, C, PERL, and JavaScript all
>return true for comparisons of null to itself. I know quite a few
>languages too
The following said using the accent of Dr. Zoidberg.
, 18 kazillion, what does it matter? How many wrongs does it take
to make it right?
*lol* But the same statement applies to the converse argument also >:)
>though I'm not sure why you threw CSS in there since
>the concept of null doesn't apply.
Ahh, I threw that in there was just because I use it and I'm trying
to impress you. :-)
Aww shucks *blushes*.
True, css doesn't have a NULL, but that just means it's NULL in the
NULL department, right? :-)
*groan* ;)
Cheers,
Rob.
No.6 | | 1076 bytes |
| 
At 3:04 PM -0400 8/26/06, Robert Cummings wrote:
Sat, 2006-08-26 at 14:23 -0400, tedd wrote:
Besides, what Alex Turner said about NULL is correct -- it's absurd
>to have NULL evaluate to anything. Just because one language allows
>absurdity doesn't mean you have to practice it.
>
language? I know for certain that PHP, C, PERL, and JavaScript all
>return true for comparisons of null to itself. I know quite a few
>languages too
The following said using the accent of Dr. Zoidberg.
, 18 kazillion, what does it matter? How many wrongs does it take
to make it right?
>though I'm not sure why you threw CSS in there since
>the concept of null doesn't apply.
Ahh, I threw that in there was just because I use it and I'm trying
to impress you. :-)
True, css doesn't have a NULL, but that just means it's NULL in the
NULL department, right? :-)
Cheers,
tedd