<?php
class articleClass {
private $author;
private $title;
function __construct($author, $title) {
$this->author = $author;
$this->title = $title;
}
function author() {
return $this->author;
}
function title() {
return $this->title;
}
}
class pageClass {
private $name;
private $author;
private $articles;
function __construct
($name, $author, array $articles) { $this->name = $name;
$this->author = $author;
$this->articles = $articles;
}
function author() {
return $this->author;
}
function children() {
return $this->articles;
}
}
function page($name) {
if ($name == 'magazine') {
new articleClass('John', 'Technology News'),
new articleClass('Joe', 'Industry News'),
new articleClass('Joe', 'More Industry News'),
new articleClass('Jane', 'Fashion News'),
);
return new pageClass('magazine', 'Joe', $articles);
} else {
throw new Exception('Page not found');
}
}
?>
<div id="automatic_list_of_articles">
<?php $page = page('magazine'); ?>
<?php foreach($page->children() as $article): ?>
<?php if($article->author() == $page->author()): ?>
<p><?php echo $article->title() ?></p>
<?php endif ?>
<?php endforeach ?>
</div>
PD9waHAKCmNsYXNzIGFydGljbGVDbGFzcyB7CgkKICBwcml2YXRlICRhdXRob3I7CiAgcHJpdmF0ZSAkdGl0bGU7CgogIGZ1bmN0aW9uIF9fY29uc3RydWN0KCRhdXRob3IsICR0aXRsZSkgewogIAkkdGhpcy0+YXV0aG9yID0gJGF1dGhvcjsKICAJJHRoaXMtPnRpdGxlID0gJHRpdGxlOwogIH0KCiAgZnVuY3Rpb24gYXV0aG9yKCkgewogIAlyZXR1cm4gJHRoaXMtPmF1dGhvcjsKICB9CiAgCiAgZnVuY3Rpb24gdGl0bGUoKSB7CiAgCXJldHVybiAkdGhpcy0+dGl0bGU7CiAgfQp9CgpjbGFzcyBwYWdlQ2xhc3MgewoKICBwcml2YXRlICRuYW1lOwogIHByaXZhdGUgJGF1dGhvcjsJCiAgcHJpdmF0ZSAkYXJ0aWNsZXM7CgogIGZ1bmN0aW9uIF9fY29uc3RydWN0KCRuYW1lLCAkYXV0aG9yLCBhcnJheSAkYXJ0aWNsZXMpIHsKICAJJHRoaXMtPm5hbWUgPSAkbmFtZTsKICAJJHRoaXMtPmF1dGhvciA9ICRhdX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