Ivar van der Burg | 1 Nov 2007 12:39
Picon

Re: Function variables in classes

Try using parent::bar2(); instead of foobar::bar2();

Op 1-nov-2007, om 12:10 heeft Paul van Haren het volgende geschreven:

> Hi there,
>
> I'm trying to execute function variables. This works fine outside  
> class
> code, but gives a fatal error when run within a class. The demo  
> code is
> here:
>
> 	<?php
>
> 	function bar1 () {
> 	    echo "Yep, in bar1() right now\n";
> 	}
>
> 	function foo1 () {
> 	    bar1();
>
> 	    $a = "bar1";
> 	    print_r ($a); echo "\n";
> 	    $a();
> 	}
>
> 	class foobar {
> 	    function bar2 () {
> 	        echo "Yep, in bar2() right now\n";
> 	    }
(Continue reading)

Paul van Haren | 1 Nov 2007 12:49
Picon

Re: Function variables in classes

I just did. The result is the same however....

Regards, Paul

--

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

rohini | 2 Nov 2007 12:52
Picon

Re: Function variables in classes


Hi paul,
  Why you are trying to use the scope resolution operator see you can use
this way simply.

Code:
******
<?php
class foobar {
    function bar2 () {
        echo "Yep, in bar2() right now\n";
    }

    public function foo2 () {
        $a = "bar2";            // Experiment 0
        $a();                   // Fatal error
    }
}
    $foo = new foobar();
    $funname = "bar2";
    $foo->$funname();  
?>
-- 
View this message in context: http://www.nabble.com/Function-variables-in-classes-tf4730655.html#a13545465
Sent from the PHP - General mailing list archive at Nabble.com.

--

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

(Continue reading)

Nathan Nobbe | 2 Nov 2007 15:16
Picon
Gravatar

Re: Function variables in classes

On 11/2/07, rohini <deepthirohini <at> gmail.com> wrote:
>
>
> Hi paul,
>   Why you are trying to use the scope resolution operator see you can use
> this way simply.
>
> Code:
> ******
> <?php
> class foobar {
>     function bar2 () {
>         echo "Yep, in bar2() right now\n";
>     }
>
>     public function foo2 () {
>         $a = "bar2";            // Experiment 0
>         $a();                   // Fatal error
>     }
> }
>     $foo = new foobar();
>     $funname = "bar2";
>     $foo->$funname();
> ?>
>

perhaps hes not working with an instance of the class.

it is perfectly reasonable to use the scope resolution operator in a
variable function.
(Continue reading)


Gmane