Re: Function variables in classes

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

 



On Nov 1, 2007, at 7:10 AM, Paul van Haren wrote:

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";
	    }

	    public function foo2 () {
	        foobar::bar2();

	        $a = "foobar::bar2";
	        print_r ($a); echo "\n";
	        $a();
	    }
	}

	foo1();


	$fb = new foobar ();
	$fb->foo2();
	?>

The error message reads:
Fatal error: Call to undefined function
foobar::bar2() in /home/paul/demo/demo.php on line 25

Is there anyone out there who can explain what's wrong in this code?

Thanks, Paul

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



I don't know if this has been said yet, but in 5.3 they added this:
Dynamic static calls: $c = "classname"; $c::someMetod();


[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