aim25 Posted July 10, 2008 Share Posted July 10, 2008 My script has many classes and functions. After a while of coding i came up with a few questions. 1. If i have a variable named $temp in function A(), is it the same as the $temp in function B()? class SOMETHING { function A() { $temp; } function B() { $temp; } } 2. Lets say i have 2 classes (class A, class B) which both extend from class MAIN. In MAIN there is a variable declared; $temp. If the value of $temp is changed in class A, then accessed in class B, is the value passed between the classes? class MAIN { var $temp; } class A extends MAIN { $this->temp = 4; } class B extends MAIN { echo $this->temp; } Quote Link to comment Share on other sites More sharing options...
trq Posted July 10, 2008 Share Posted July 10, 2008 1: No, variables declared within functions are only available within said functions. 2: No, to achieve that class B would need to extend class A. Quote Link to comment Share on other sites More sharing options...
aim25 Posted July 10, 2008 Author Share Posted July 10, 2008 TY, that clears makes things a lot more clear. Quote Link to comment Share on other sites More sharing options...
btherl Posted July 10, 2008 Share Posted July 10, 2008 To add to 2, a class definition is just a definition. You can't set a variable in a definition of a class (except to set a default value). You can only set a variable in an instance of a class. If you have an instance of class A and an instance of class B, then their variables are totally separate, even if their classes both extended the same parent. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.