stricks1984 Posted May 12, 2008 Share Posted May 12, 2008 Hello, I have the following directory structure: /Program.php /Sections/Section.php /Sections/Inputs/Input.php In Program.php I have the following: require('Sections/Inputs/Input.php'); require('Sections/Section.php'); ... array_push($this->sections, new Section('ff', 'ff', new Input('title', 'text'))); // Where problem begins. In Section.php I have: private $input_type; private $id; private $headerTitle; function __construct($id, $header, $input){ $this->id = $id; $this->headerTitle = $header; $this->input_type = input; $this->input_type->make(); // DOES NOT WORK // PHP Fatal error: Call to a member function make() on a non-object } Code for Input.php: class Input { private $display; private $id; public function __construct($id){ $this->id = $id; $this->display = ''; } public function make(){ error_log('Gets called, during creation, but can't access this method'); } public function display(){ return $this->display; } public function getID(){ return $this->id; } I know this has something to do with reference and such, but I just don't understand what I'm doing wrong. I'm running PHP 5>. Any help would greatly be appericated. Link to comment https://forums.phpfreaks.com/topic/105308-solved-passing-an-object-by-parameter-creates-an-object-but-cannot-access-the-methods/ Share on other sites More sharing options...
stricks1984 Posted May 12, 2008 Author Share Posted May 12, 2008 If I call a bogus method: $this->input_type->bogus(); I get: Call to undefined method Input::bogus() With non-bogus: PHP Fatal error: Call to a member function make() on a non-object Link to comment https://forums.phpfreaks.com/topic/105308-solved-passing-an-object-by-parameter-creates-an-object-but-cannot-access-the-methods/#findComment-539270 Share on other sites More sharing options...
flyhoney Posted May 12, 2008 Share Posted May 12, 2008 $this->input_type = input; should be $this->input_type = $input; Link to comment https://forums.phpfreaks.com/topic/105308-solved-passing-an-object-by-parameter-creates-an-object-but-cannot-access-the-methods/#findComment-539278 Share on other sites More sharing options...
stricks1984 Posted May 12, 2008 Author Share Posted May 12, 2008 Sorry, that's how it is. It was a typo. Link to comment https://forums.phpfreaks.com/topic/105308-solved-passing-an-object-by-parameter-creates-an-object-but-cannot-access-the-methods/#findComment-539281 Share on other sites More sharing options...
stricks1984 Posted May 12, 2008 Author Share Posted May 12, 2008 When I do echo print_r($input); I get the following: Input Object ( [type:private] => text [display:private] => [id:private] => title [display] => [js] => ) Link to comment https://forums.phpfreaks.com/topic/105308-solved-passing-an-object-by-parameter-creates-an-object-but-cannot-access-the-methods/#findComment-539285 Share on other sites More sharing options...
stricks1984 Posted May 13, 2008 Author Share Posted May 13, 2008 Ok, so I found the problem... In Section.php : private $input_type; // The object being passed as parameter. Needed to be either protected or public. Wow, I don't know how I didn't see that. Link to comment https://forums.phpfreaks.com/topic/105308-solved-passing-an-object-by-parameter-creates-an-object-but-cannot-access-the-methods/#findComment-539799 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.