Re: call_user_func possible bug in PHP5Rc1 PHP5RC2, am I crazy?

From: Date: Tue, 27 Apr 2004 19:09:08 +0000
Subject: Re: call_user_func possible bug in PHP5Rc1 PHP5RC2, am I crazy?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-184794@lists.php.net to get a copy of this message
My first question would be: are you running the latest snapshot of PHP 5RC2? You can download it from http://snaps.php.net Secondly, if I'm not mistaken, you have to create an instance of the object in order to use the $this keyword. So, that's why you're getting the error "Using $this when not in object context". If you want to statically call a method of a class (even with call_user_func), you cannot use the $this keyword in the method. Try using test_call_user_function::created instead. This is going to create a problem, though, because the variable "created" has not be instantiated since the class was never created as an object. I would suggest that you read up on object-oriented programming and learn a little more about how things work. You really need to do: $test = new test_call_user_func(); to create the object. Then you can use $test to access the methods of that object. Anyone else, back me up on this if I'm wrong. Ben Vincent A. Wixer wrote:
Hey there Guys, I've been seeing some behavior in PHP5 that doesn't seem to jive with past (PHP4) behavior of call_user_func. Basically, it feels like methods of a class are being called, but not in an instance of the class. I'm afraid no one else on my team is testing php5 so I can't check with them to see if I'm doing something wrong. I'd really appreciate if anyone else test driving PHP5 RC1 or RC2 could tell me if they're getting the same "not in object context" message. I'd certianly hate to submit an bad bug. My Code: <?php
    // -------------------------------------------------------
    class test_call_user_func
    {
        var $created = false;
        function __construct()
        {
            $this->created = true;
        }
        function isCreated()
        {
            $ret = $this->created;
            return $ret;
        }
    }
    $my_args = array ('first' => 1, 'second' => 2, 'third' => 3);
    $function = array('test_call_user_func', 'isCreated');
    print ("I have a return of isCreated [" . call_user_func($function) . "]"  );
?> My Results: vfabello@godot:~/workspace/loki/root$ php5rc1 test3.php Fatal error: Using $this when not in object context in /home/vfabello/workspace/loki/root/test3.php on line 16 vfabello@godot:~/workspace/loki/root$ php5rc2 test3.php Fatal error: Using $this when not in object context in /home/vfabello/workspace/loki/root/test3.php on line 16 (php5rc1 and php5rc2 are ln -s to their appropriate binaries, configure parameters were: './configure' '--with-zlib' '--enable-wddx' '--enable-bcmath' '--with-openssl' '--with-bz2' '--enable-memory-limit' '--prefix=/usr/share/php5rc2' '--with-config-file-path=/etc/php5rc2/apache' '--with-exec-dir=/usr/lib/php5rc2/libexec' '--with-mysql-sock=/var/run/mysqld/mysqld.sock' '--with-mysql' '--with-apxs=/usr/bin/apxs' '--with-mysql=/usr/share/mysql' '--with-libxml-dir=/usr/lib' '--enable-soap' '-with-config-file-path=/usr/share/php5rc2' ) Thanks Vincent hrvinnie NOSPAM @ yahoo DOT NOSPAM com
-- Regards, Ben Ramsey http://benramsey.com http://www.phpcommunity.org/wiki/People/BenRamsey

« previous php.general (#184794) next »