define and objects!

From: Date: Sun, 29 Apr 2007 23:04:30 +0000
Subject: define and objects!
Groups: php.internals 
Request: Send a blank email to internals+get-29105@lists.php.net to get a copy of this message
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.

« previous php.internals (#29105) next »