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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:40:58+00:00 2026-06-03T04:40:58+00:00

How can I use __get() to return null in multilevel object property accessing the

  • 0

How can I use __get() to return null in multilevel object property accessing the case like this below?

For instance, this is my classes,

class property 
{

    public function __get($name)
    {
        return (isset($this->$name)) ? $this->$name : null;
    }
}


class objectify
{

    public function array_to_object($array = array(), $property_overloading = false)
    {
        # if $array is not an array, let's make it array with one value of former $array.
        if (!is_array($array)) $array = array($array);

        # Use property overloading to handle inaccessible properties, if overloading is set to be true.
        # Else use std object.
        if($property_overloading === true) $object = new property();
            else $object = new stdClass();

        foreach($array as $key => $value)
        {
            $key = (string) $key ;
            $object->$key = is_array($value) ? self::array_to_object($value, $property_overloading) : $value;
        }


        return $object;

    }
}

How I use it,

$object = new objectify();

$type = array(
    "category"  => "admin",
    "person"    => "unique",
    "a"         => array(
        "aa" => "xx",
        "bb"=> "yy"
    ),
    "passcode"  => false
);


$type = $object->array_to_object($type,true);
var_dump($type->a->cc);

result,

null

but I get an error message with NULL when the input array is null,

$type = null;
$type = $object->array_to_object($type,true);
var_dump($type->a->cc);

result,

Notice: Trying to get property of non-object in C:\wamp\www\test...p on line 68
NULL

Is it possible to return NULL in this kind of scenario?

  • 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-06-03T04:41:00+00:00Added an answer on June 3, 2026 at 4:41 am

    You can can return new property instead of null

     public function __get($name)
        {
            return (isset($this->$name)) ? $this->$name : new property();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there an ide/site that I can use to analyse code below and get
Try to download this page: http://www.4shared.com/get/B4AgMkcw/cookies.html I can use wget/firefox to get the whole
Currently have this code defining getter/setter for an object's selectedID property. The object is
How to implement IEnumerator on this class so that I can use it in
In Python I can use get method to get value from an dictionary without
I can use GetModuleHandle to get its base offset, but I also need to
Which function can I use to get the content of a plain text file?
For example to get the favicon of a site I can use http://www.google.com/s2/favicons?domain= and
I'm wondering how you can use Yahoo Pipes to get any tweets than contain
HTML Javascript question to get the selected value of a input-select I can use

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.