oop - PHP object scope -
can explain me concept of object scope in php? i'm new objects in php , reason ask because able create object within if statement, , access object outside scope of if statement.
example:
//only create object if condition met if ($conditiontrue){ $mybook = new book('php dummies','softcopy'); } $mybook.read();
i have though generate error didn't.
some background question
i trying figure out how determine constructor call depending on condition met. conceivable way introduce if statement
doing that, thought impose issue of scope
didn't , i'm wondering why..
in php, if doesn't have own scope. yes, if define inside if statement or inside block, available if defined outside (assuming, of course, code inside block or inside if statement gets run).for more php scope, read variable scope manual page.
Comments
Post a Comment