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 981555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:33:36+00:00 2026-05-16T04:33:36+00:00

I am new to php and currently I am reading Wrox Professional PHP 5.

  • 0

I am new to php and currently I am reading Wrox Professional PHP 5.

Can anyone explain me the following code ?

<? php

abstract class PropertyObject
{
//Stores name/value pairs that hook properties to database field names
protected $propertyTable=array();

//List of properties that have been modified.
protected $changedProperties=array();

//Actual data from the database.
protected $data;

//Any validation errors that might have occured.
protected $errors=array();

public function __construct($arData)
{
     $this->data=$arData;
}

function __get($propertyName)
{
     if(!array_key_exits($propertyName,$this->propertyTable))
     {
          throw new Exception("Invalid property \"$propertyName\" !");
     }

     if(method_exists($this,'get'.$propertyName))
     {
          return call_user_func(array($this,'get'.$propertyName));
     }
     else
     {
          return $this->data[$this->propertyTable[$propertyName]];
     }
}

function __set($propertyName,$value)
{
     if(!array_key_exits($propertyName,$this->propertyTable))
     {
          throw new Exception("Invalid property \"$propertyName\" !")
     }

     if(method_exits($this,'set'.$propertyName))
     {
     return call_user_func(array($this,'set'.$propertyName),$value);
     }
     else
     {
     //If the value of the property really has changed and it's not already in the changedProperties array, add it.

          if($this->propertyTable[$propertyName] !=$value && !in_array($propertyName,$this->changedProperties))
          {
               $this->changedProperties[]=$propertyName;
          }

          //Now set the new value
          $this->data[$this->propertyTable[$propertyName]]=$value;

     }
}

}
?>

I can’t understand the code inside assessor get and set methods.

  • 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. Editorial Team
    Editorial Team
    2026-05-16T04:33:37+00:00Added an answer on May 16, 2026 at 4:33 am

    The __get magic method is called when a property of the object is requested but it wasn’t declared or specifically assigned (for dynamic properties). This implementation:

    • First tries to see if the logical property exists as an entry in the actual declared property named $propertyTable.
    • If it doesn’t exist, it throws an exception, therefore leaving the method,
    • If it exists and additionaly exists a method named 'get'.$propertyName (i.e., "get" concatenated with the request property name), that method is called and its value is returned.
    • If it exists but there’s no such method, it returns the value of the entry with key $propertyName in the declared property $propertyTable.

    Given this, I think you can figure __set out. See Magic Methods in the PHP manual.

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

Sidebar

Related Questions

Currently, I am working on restructuring an existing code base. I'm new to php
Currently I using the following code to get my JSON output from MySQL. <?php
i need help in debugging my code. Im new into php and im currently
I'm completely new to OOP PHP and currently reading PHP Objects, Patterns and Practice.
I'm new to PHP and I am currently creating a PHP web application for
I am VERY new to PHP, I'm currently working on a service, part which
I'm currently building a new online Feed Reader in PHP. One of the features
I'm currently trying out Aptana Studio 3 for PHP development (I'm pretty new to
I am new to Object Oriented PHP. Currently I am making a login script
I'm currently reading a regularly updated XML file with PHP (simpleXML). I'd like to

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.