Jump to content

[SOLVED] Passing an Object by parameter creates an object, but cannot access the methods.


stricks1984

Recommended Posts

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.

 

 

 

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.