Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 89331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:41:59+00:00 2026-05-10T22:41:59+00:00

I have a class named Page with a private property currently called _pageData which

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T22:42:00+00:00Added an answer on May 10, 2026 at 10:42 pm
    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).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a class named Frog, it looks like: public class Frog {
I've got a philosophical programming problem. Let's say I have a class named Employees.
I've just started to learn about tie . I have a class named Link
If I have class names such as left, right, clear and xhtml like <a
I have this sample text, which is retrieved from the class name on an
I have a class which retrieves the data from DB. [Table(Name = Ilanlar)] public
I have page like this ... <Page x:Class=WPFTestRig.Page1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml Title=Page1> <Grid> <StackPanel> <ComboBox
i have generated a Linq to Sql class which looks like this. so i
I have a login.jsp page which contains a login form. Once logged in the
I have a simple test page in my Silverlight 4 application in which I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.