joesaddigh Posted April 20, 2010 Share Posted April 20, 2010 Hi, Is there any way of making a file which contains a member variable which I can then access by using a getter or setter function. If so can I do this from another file. For example in C++ you can make a private variable and access it from another class by using a public getter method which I could access via a pointer to that class. Is there something simmilar that I could do with php?? Thanks Joe Link to comment https://forums.phpfreaks.com/topic/199159-variable-scope/ Share on other sites More sharing options...
Ken2k7 Posted April 20, 2010 Share Posted April 20, 2010 Yes. first file class A { private $a = 4; public function getA () { return $this->a; } } second file require 'file1'; $obja = new A(); echo $obja->getA(); Link to comment https://forums.phpfreaks.com/topic/199159-variable-scope/#findComment-1045301 Share on other sites More sharing options...
joesaddigh Posted April 20, 2010 Author Share Posted April 20, 2010 I see.. It is litterally the same syntax.. I will use this from now on. I have been being lazy and storing session variables which is stupid. I need to get into the OO side of php. Thanks very much for your help Joe Link to comment https://forums.phpfreaks.com/topic/199159-variable-scope/#findComment-1045304 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.