Reference calling class

<?php

class CallingClass{
public $instance_class;
public function __construct(){
$this->instance_class = new InstanceClass($this);
}
public function show_new_data($data){
echo 'This in the data set in an instance created by this class: ' . $data;
}
}

class InstanceClass{
protected $_calling_class;
public function __construct(CallingClass $calling_class){
$this->_calling_class = $calling_class;
}
public function add_data($data){
$this->_calling_class->show_new_data($data);
}
}

$test = new CallingClass();
$test->instance_class->add_data('Hello World');

?>

0 Comments

You must be logged in to post a comment.