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

  • SEARCH
  • Home
  • 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
  • 2 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

I have a class named CropImageView which is extended from ImageView . but the
I have a class named FirstViewController which is a subclass of UIViewController and I
I have a Class named Constants that contains all the constant variable in my
I have a class named Person and in this class is the property PersonName
I have a base class ReportElement which has type property: public abstract class ReportElement
I have a page with several tables on it with the same class name.
I have multiple datepickers in one page. I user class name to set the
i have class named Group i tried to test configuration: var cfg = new
I have a Class named Question and a related Class named Answers. I want
I have a class named baseClass. From this class I inherit a class names

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.