strazdinjsh Posted April 8, 2011 Share Posted April 8, 2011 could anyone advice how to extend the php class who contains variable? sample below does not work. class test1 extends test2($index){ public function output($index){ echo $index; } } class test2{ public function __construct($index){ echo $index; } } $test = new test1; $test->output('My Test2'); $test->test2('My Test1'); Link to comment https://forums.phpfreaks.com/topic/233063-php-class-extending/ Share on other sites More sharing options...
gristoi Posted April 8, 2011 Share Posted April 8, 2011 try: class test1 { protected $_index; public function __construct($index) { $this->_index = $index; } } class test2 extends test1 { public function output() { echo $this->_index; } } Link to comment https://forums.phpfreaks.com/topic/233063-php-class-extending/#findComment-1198633 Share on other sites More sharing options...
strazdinjsh Posted April 11, 2011 Author Share Posted April 11, 2011 i have got it sorted, thanks Link to comment https://forums.phpfreaks.com/topic/233063-php-class-extending/#findComment-1200002 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.