[email protected] 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? } Link to comment https://forums.phpfreaks.com/topic/179155-calling-strings-from-other-php-class/ 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; } Link to comment https://forums.phpfreaks.com/topic/179155-calling-strings-from-other-php-class/#findComment-945186 Share on other sites More sharing options...
[email protected] 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? Link to comment https://forums.phpfreaks.com/topic/179155-calling-strings-from-other-php-class/#findComment-945188 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 Link to comment https://forums.phpfreaks.com/topic/179155-calling-strings-from-other-php-class/#findComment-945197 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. Link to comment https://forums.phpfreaks.com/topic/179155-calling-strings-from-other-php-class/#findComment-945205 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.