class Page {
public $title = '';
public $keywords = array();
public $content = '';
// etc.
}
$page = new Page();
echo '<title>' . $page->title . '</title>';
echo $page->content;
Or you can use accessors/get-set and the like to protect your data, allow it to be modified with persistence, or whatever. This allows for lazy initialization and lazy writing (not sure if there's a proper term for the latter). Example:
class Page {
private $data = array('title' => '', 'keywords' => array(), 'content' => '');
public __get($name) {
if(isset($this->data[$name]))
return $this->data[$name];
/* You probably want to throw some sort of PHP error here. */
return 'ERROR!';
}
}
$page = new Page();
echo '<title>' . $page->title . '</title>';
echo $page->content;
(See overloading in the PHP5 manual for more details.)
Note you can hide $data members or even modify them or add new ones ($page->contentHTML could transform markdown to HTML, for example).
Using the name _pageData
is redundant for a Page class. You already know it's a page, so you're repeating information ($currentPage->_pageData vs. $currentPage->data).
I also find associative arrays a little messier for this kind of thing, but they may be needed if you want a really dynamic system. Regardless, you can implement your template system to access class members by name ($member = 'title'; echo $page->$member; // echoes $page->title
), assuming this is what you wanted the array for (other than an easy database query, which you can use list() for).