Re: Re: Function variables in classes

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

 



OK guys, thanks for all your inputs. 

Based on your guidance, I have tested the following code with a
series of variations: 

	class foobar {
    		function bar2 () {
        		echo "Yep, in bar2() right now\n";
    		}

    		public function foo2 () {
        		$a = "bar2";            // Experiment 0
        		$a();                   // Fatal error
    		}
	}

And the variations:
      $a = "bar2";            // Experiment 0
      $a();                   // Fatal error: Call to undefined function bar2()

      $a = "foobar::bar2";    // Experiment 1
      $a();                   // Fatal error: Call to undefined function bar2()

      $a = "bar2";            // Experiment 2
      eval($a."();");         // Fatal error: Call to undefined function bar2()

      $a = "foobar::bar2";    // Experiment 3
      eval($a."();");         // Works but far from elegant

      $a = "bar2";            // Experiment 4
      $this->$a();            // Works fine

      $a = "bar2";            // Experiment 5
      self::$a();             // Works fine

So, I have a working solution right now. But I still don't understand the
essence of the differences between experiment #1 and #4. Also, I don't
understand the need to specify the class name in experiment #3, coming
from #2. Functions bar2() and foo2() are part of the same class foobar,
and I would assume that the name 'bar2' would be in scope of the function
foo2.

BTW: I'm running PHP v5.2.0-8 build and distributed by Debian (etch1).

Thanks again and regards, Paul.

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


[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