salman_ahad@yahoo.com Posted October 27, 2009 Share Posted October 27, 2009 I have test1.php{ $string1; $string2; .... ... //10 strings in this class $string10; } Another class test2.php { ..... .... I want to use those 10 strings here, how should I do it? } Quote Link to comment Share on other sites More sharing options...
joel24 Posted October 27, 2009 Share Posted October 27, 2009 you'd have to write a function which shares those variables. public function shareStrings() { $strings = array($this->string1, $this->string2, $this->string3.... $this->string10); return $strings; } Quote Link to comment Share on other sites More sharing options...
salman_ahad@yahoo.com Posted October 27, 2009 Author Share Posted October 27, 2009 Where exactly I have to write this function? Can I write this is any class or separate. And how do I call it where I need it? Quote Link to comment Share on other sites More sharing options...
joel24 Posted October 27, 2009 Share Posted October 27, 2009 you have to put it inside the class which has the $string1 - 10 variables. then to call it you need to create an object i.e. $object1 = new test1(constructor details); then you can use $array = $object1->shareStrings(); which will put the strings into $array. read up on it. http://www.php.net/manual/en/language.oop5.basic.php Quote Link to comment Share on other sites More sharing options...
trq Posted October 27, 2009 Share Posted October 27, 2009 If your asking this question I highly doubt you even need the classes you have. 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.