PDA

View Full Version : problem in objects ?


PHPycho
05-27-2007, 01:18 PM
Hello forums !!
i had a problem while creating a objects..
i usually create the objects at the top of the index.php page and all other files are included in the index.php page..
suppose i create a object say :
$obj1 = new MyClass();

while using this object in the another page say cat.php which is included in the index.php.
if(isset($_POST['SUBMIT'])){
global $obj1;
$obj1->save();
}

i had to make the object global, other it doesnt work..inside the functions its obvious to make the varible global in order to use it..but i had to use it in each if() condition.....
Any idea avoid this situation of making global in case of if(), while() etc conditions
Awaiting for your great help
Thanks in advance to all of you

GJay
05-27-2007, 01:28 PM
This is the javascript forum, your code is PHP....

'if' blocks don't have their own scope in PHP (nor do 'while'), so there must be something else in your code that you're not explaining. Can you post more of your code or, and this will make it easier to help you, put together as small an example as possible that demonstrates your problem.