Edit report at https://bugs.php.net/bug.php?id=63990&edit=1

 ID:                 63990
 Updated by:         johan...@php.net
 Reported by:        rok at andree dot si
 Summary:            Function returns wrong when deailing with class
                     magic methods
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            Scripting Engine problem
 Operating System:   Linux
 PHP Version:        5.3Git-2013-01-15 (snap)
 Block user comment: N
 Private report:     N

 New Comment:

isset() and empty() call the __isset() magic method, not __get.


Previous Comments:
------------------------------------------------------------------------
[2013-01-15 12:27:20] rok at andree dot si

Description:
------------
---
>From manual page: 
>http://www.php.net/function.empty#refsect1-function.empty-description
---

When testing a property of a class with empty(),
when this property is served by __get magic method
when this property is NOT EMPTY

empty() will return TRUE
and display no error or warning

This has been tested on:
PHP 5.3.6-13ubuntu3.7 with Suhosin-Patch (cli) (built: May  4 2012 00:50:06) 
and
http://writecodeonline.com/php/


Test script:
---------------
$v = "11.10.2012 13:26:21";

$test = new a();
$test->b = $v;

echo $test->b;

$r = empty($test->b);

var_dump($r);

class a {

protected $b;

/*
         * Magic
         */
        public function __get($property) {
          if (property_exists($this, $property)) {
      return $this->$property;
          }
  }

        /*
         * Magic
         */
  public function __set($property, $value) {
    if (property_exists($this, $property)) {
      $this->$property = $value;
    }
  }
  
}

Expected result:
----------------
11.10.2012 13:26:21bool(false) 
OR
Error along the lines of:
Fatal error: Can't use function return value in write context on line N

Actual result:
--------------
11.10.2012 13:26:21bool(true) 


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=63990&edit=1

Reply via email to