I have a class named Page with a private property currently called _pageData which stores all the information (such as title, content, keywords etc).
However, this to me doesn’t look so good when I refer to it $this->_pageData. I want to think of a better name, and I’d imagine there would probably be a standard or ‘best practice’ name/prefix/suffix for these sorts of things. I thought about ‘_assets’.
May I ask what you have used in the past, an unambiguous name that hasn’t made you down the track add some data to it and go ‘Oh no, now my array has data in it that’s outside the scope of the variable name’. This has happened to me a few times so I’d like to see what has been proven to work.
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:
(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
_pageDatais 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).