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');

?>

Observer pattern

<?php

/* Observer Interface */
interface Observer{
function register_change($subject,$args);
}

/* Observable Interface */
interface Observable{
function add_observer($observer);
}

/* Inbox Notifier */
class InboxNotifier implements Observer{
public function register_change($subject,$args){
echo "A new message has been added to your inbox: <br>$args";
}
}

/* Inbox Subject */
class MyInbox implements Observable{
private $_observers = array();
public function add_observer($observer){
$this->_observers []= $observer;
}
public function add_message($message){
foreach($this->_observers as $observer) $observer->register_change($this,$message);
}
}

$my_inbox = new MyInbox();
$my_inbox->add_observer(new InboxNotifier());
$my_inbox->add_message('This is a test message');
?>