php - OOP not being initiated into variable for later object access -


i have feeling stupid mistake had me stalled last 24 hours; have class works on every other page use on. using very small version of class while creating ipn listener paypal subscriptions.

the problem i'm having after creating new instance of class in variable (the exact same way on other pages), , try access it, receive error saying i'm trying use non object variable object.

the condensed version;

creating new instance of class:

$utilities = new utilitys(new db("mysql:host=xcensored;dbname=xcensored", "xcensored", "xcensored")); 

using object

$a = $utilities->db->run("select * xcensored xcensored =:id", array(':id' => (int)trim($xcensored))); 

error log message

php notice:  undefined variable: utilities in xx/xx/xx/xx.php   php notice:  trying property of non-object in xx/xx/xx/xx.php   php fatal error:  call member function run() on non-object in xx/xx/xx/xx.php  

looks you're using 'utilities' , 'utilitys' interchangeably... unless that's typo in question?

edit: actually, no, ignore me. didn't read properly.

edit: have tried debug this? put few var_dump() statements in different places of db , utilitys classes try , narrow down things go awry. maybe instantiate db class in variable , pass variable 'new utilitys()'. check db variable holds object of db first. if does, problem inside utilitys class.

edit: ok, if have tried following, correct? :

$db = new db("mysql:host=xcensored;dbname=xcensored", "xcensored", "xcensored");
$utilities = new utilitys($db);

var_dump($db); // have db object in $db
var_dump($utilities) // comes out here

solved original poster: "...i figured out now, , silly error; variable scope, had use php's global command work"


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -