Hi, I'm new to objects in PHP and not sure how to go about passing one object to another. The closest I've gotten is getting both objects written to the page, but seperately. What I want to do is set one object (an image) as an attribute of another (a page). The image object should appear within the code output by the page object, but that's not happening- what is happening is that the image object gets written to the page first, followed by the page object.
(code simplified for example)
[font=arial]
<?php
class page {
function page($pageContent) {echo "foo <br />\n $pageContent <br />\n bar";}
}
class image {
function image() {echo "<img src='foo.jpg' />";}
}
$page = new page(new image());
?>
[/font]
the above code writes this to the page:
[broken img]foo
Object
bar
I also tried returning the image object rather than echoing it, along with the "&" operator in the return function definiton:
[font=arial]
<?php
class page {
function page($pageContent) {echo "foo <br />\n $pageContent <br />\n bar";}
}
class image {
function &image() {return "<img src='foo.jpg' />";}
}
$page = new page(new image());
?>
[/font]
That writes this to the page:
foo
Object
bar
the image tag doesn't write at all-
any thoughts?