$obj = new myObj(); // create my object $obj->set_env($value); // works fine function test { global $obj; $obj->set_env($value2); // Doesn't work, produces below error. }