define and objects!

php.internals

MaaSTaaR

19 years ago
Hello ... Firstly sorry for my bad English, my friend request from me to send this suggestion for PHP developer. The suggestion is support use constant as object, for example : class HelloWorld { function start() { echo 'Hello World'; } } define('OBJ',new HelloWorld); OBJ->start(); this will be good when we use object inside class, we will not need use global or $this, for example. With normal way : class MainClass { function One() { echo 'One'; } function Two() { echo 'Two'; } } $Main = new MainClass; class AnotherClass { function P() { global $Main; // Note this line $Main->One(); } } With suggested way : class MainClass { function One() { echo 'One'; } function Two() { echo 'Two'; } } define('MAIN',new MainClass); class AnotherClass { function P() { MAIN->One(); // use it directlly without global or $this } } --------------------------------- Ahhh...imagining that irresistible "new car" smell? Check outnew cars at Yahoo! Autos.

David Coallier

19 years ago
On 4/29/07, MaaSTaaR <el7zndotcom@yahoo.com> wrote:
> Hello ... > > Firstly sorry for my bad English, my friend request from me to send this suggestion for PHP developer. > > The suggestion is support use constant as object, for example : > > class HelloWorld > { > function start() > { > echo 'Hello World'; > } > } > > define('OBJ',new HelloWorld); > > OBJ->start(); > > this will be good when we use object inside class, we will not need use global or $this, for example. > > With normal way : > > class MainClass > { > function One() > { > echo 'One'; > } > > function Two() > { > echo 'Two'; > } > } > > $Main = new MainClass; > > class AnotherClass > { > function P() > { > global $Main; // Note this line > > $Main->One(); > } > } > > With suggested way : > > class MainClass > { > function One() > { > echo 'One'; > } > > function Two() > { > echo 'Two'; > } > } > > define('MAIN',new MainClass); > > class AnotherClass > { > function P() > { > MAIN->One(); // use it directlly without global or $this > } > } > > > > --------------------------------- > Ahhh...imagining that irresistible "new car" smell? > Check outnew cars at Yahoo! Autos.
You could just do class Main { public static function P() { echo 'woo'; } } class Yeah { public function S() { Main::P(); } }
-- David Coallier, Founder & Software Architect, Agora Production (http://agoraproduction.com) 51.42.06.70.18