RE: Brain Death - [PHP] functions classes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

-----Original Message-----
From: Robert Cummings [mailto:robert@xxxxxxxxxxxxx] 
Sent: 26 August 2006 16:42
To: Alex Turner
Cc: php-general@xxxxxxxxxxxxx
Subject: Re:  Brain Death - [PHP] functions classes

On 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.
-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'


-- 
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.405 / Virus Database: 268.11.6/427 - Release Date: 24/08/2006
 

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.405 / Virus Database: 268.11.6/427 - Release Date: 24/08/2006
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux