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.          |
`------------------------------------------------------------'

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

Reply via email to