Re: PHP 4 to 5 class issues involving static methods and $this

From: Date: Thu, 18 Nov 2004 07:13:36 +0000
Subject: Re: PHP 4 to 5 class issues involving static methods and $this
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-202384@lists.php.net to get a copy of this message
Chris wrote:
How can I rewrite my class for PHP 5 to emulate the functionality I had in PHP 4 in an error free way?
Have you tried this: function format_string($string) {
    // format the string...
    $result = string;
    if (isset($this)) $this->elements[] = $result;
    return $result;
} In this form you can check the existance of $this. If you call the method statically then $this is not present and the elements array is not filled. If you call it non-statically then $this is present and elements is filled. The same you can do with show_all().

« previous php.general (#202384) next »