Posted by Jerry Stuckle on 01/13/07 05:40
paul.j wrote:
> I have
>
> class thechild{
> function sayTest()
> {
> parent::test(); // this right???
> }
> }
>
> class theparent{
> function test()
> {
> echo "test";
> }
> function __construct()
> {
> $e = new thechild();
> $e->sayTest();
> }
> }
>
> How do i get this to work ? I am trying to get a one class (A) to
> create another class (B) within it, but the class B must be able to
> call a function from class A. Any ideas?
>
> Thanks
> Paul Jenkins
> www.pjenkins.co.uk
>
No, this is not correct. You have no parent-child relationship between
them; theparent's constructor just creates a thechild object (then
throws it away when the constructor exits.
And think about this - what happens if you just had:
function myfunc() {
$c = new thechild();
...
}
IOW, you're creating a new thechild object outside of a theparent
object. What would the statement "parent::text()" do then?
Look at the "extends" keyword. Use it to derive thechild from theparent.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
[Back to original message]
|