FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » General » PHP discussions » PHP object scope
Show: Today's Messages :: Unread Messages :: Show Polls :: Message Navigator
| Subscribe to topic | Bookmark topic 
Return to the default flat view Create a new topic Submit Reply
PHP object scope [message #168330] Thu, 18 April 2013 02:55
Jack Hard is currently offline  Jack Hard
Messages: 7
Registered: December 2012
Karma:
Junior Member
add to buddy list
ignore all messages by this user


Can somebody explain to me the concept of object scope in PHP? I'm very new to objects in PHP and the reason I ask is because I was able to create an object within an if statement, and then access the object outside the scope of the if statement.

Example:

//only create object if some condition is met
if ($conditionTrue){
$myBook = new Book('PHP for Dummies','softcopy');
}

$myBook.read();

I would have though that this would generate an error but it didn't.

Some background to my question

I was trying to figure out how to determine which constructor to call depending on the condition that is met. The only conceivable way was to introduce an if statement but doing that, I thought would impose the issue of scope which it didn't and I'm just wondering why..
[Message index]
 
Unread Message
Previous Topic: Problems getting LDAPS to work
Next Topic: SQL optimization join
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Mon Oct 16 20:23:57 EDT 2017

Total time taken to generate the page: 0.00620 seconds