On Sat, Oct 15, 2011 at 03:01:44PM +0100, Alain Williams wrote:
> Well, that is what I think that I need. Please let me explain what I am 
> trying to do
> and tell me how to do it or a better way of doing it.
> ......

I have solved it. The problem is basically one of ensuring that properties are 
the same
value when accessed via the parent or child class ... be that to get or set a 
So I solved the problem by making the properties in the child class references 
to the
ones in the parent class.

Methods are not a problem - inheritance just works fine.

To do this, pass the instance of the parent class to the child class 
constructor and use
a reflection class to determine the properties in the parent class. This will 
not work
properly if the child class overrides a property of the parent class ... this 
does not
worry me.

class Screen {
    public $screen;

class Form extends Screen {
    function __construct(&$s) {
      $sr = new ReflectionClass($s);

      foreach($sr->getProperties(ReflectionProperty::IS_PUBLIC | 
ReflectionProperty::IS_PROTECTED) as $p)
        $this->{$p->name} = &$s->{$p->name};

$s = new Screen(....);
$s->AddJsVar('Date', '15 Oct 2011');

$f1 = new Form($s);

$f1->screen = 'something'; // this assigns the property in $s.

Comments ?

Alain Williams
Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT 
+44 (0) 787 668 0256  http://www.phcomp.co.uk/
Parliament Hill Computers Ltd. Registration Information: 
#include <std_disclaimer.h>

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to