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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:05:03+00:00 2026-06-13T03:05:03+00:00

<?php class Magic_Methods { protected $meta; public function __construct() { $this->meta = (object) array(

  • 0
<?php

class Magic_Methods
{
    protected $meta;

    public function __construct() 
    {
        $this->meta = (object) array(
            'test' => 1
        );
    }

    public function __isset($name) 
    {
        echo "pass isset {$name} \n";

        return isset($this->$name);
    }

    public function __get($name) 
    {
        echo "pass get {$name} \n";

        return $this->$name;
    }
}

$mm = new Magic_Methods();

$meta = empty($mm->meta->notExisting);

var_dump($meta);

echo "||\n";

$meta = empty($mm->meta);

var_dump($meta);

The snippet above does not work as expected for me. Why would the first empty() ommit the __isset? I get this:

pass get meta 
bool(true)
||
pass isset meta 
pass get meta 
bool(false)

I would expected identical results or another pass at the __isset, but not a direct call to __get. Or am I missing something here?

  • 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-13T03:05:04+00:00Added an answer on June 13, 2026 at 3:05 am

    On the first call to empty, it is trying to “get” meta so it can test if “notExisting” is empty inside of meta. $meta is just a generic std class with no magic methods so you are not going to get any output (it doesn’t call Magic_Methods::__get as $meta isn’t an instance of Magic_Methods).

    On the second call to empty, it checks to see if meta is set, which it is and so isset returns true. As claudrian says, empty depends on the value so it then tries to “get” meta next so it can determine if the value is empty. It is not empty and so empty returns false. If you change the second call to empty, to isset, it only calls isset which returns true.

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

Sidebar

Related Questions

the class, which is content.php class content { private $vars = array(); public function
Here is the class: functions.php class buildPage { public function Set($var,$val){ $this->set->$var = $val;
Given the following in PHP: <?php class foo { public $bar; function __construct() {
<?php abstract class AbstractClass { public function __get($theName) { return (isset($this->$theName)) ? $this->$theName :
I have a php class, RegistrationController, <?php class RegistrationController extends ParentController { function __construct()
I am having PHP class class SurveyQuestion extends CActiveRecord { public function relations() {
Which PHP SPL interface allows objects to do this: $object->month = 'january'; echo $object['month'];
I have a PHP class that stores a complex multidimensional array, and rather than
I'm using this php class ( http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php ) for creating the different sized images
I've got a class Foo with public and protected properties. Foo needs to have

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.