From:             rok at andree dot si
Operating system: Linux
PHP version:      5.3Git-2013-01-15 (snap)
Package:          Scripting Engine problem
Bug Type:         Bug
Bug description:Function returns wrong when deailing with class magic methods

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 bug report at https://bugs.php.net/bug.php?id=63990&edit=1
-- 
Try a snapshot (PHP 5.4):   
https://bugs.php.net/fix.php?id=63990&r=trysnapshot54
Try a snapshot (PHP 5.3):   
https://bugs.php.net/fix.php?id=63990&r=trysnapshot53
Try a snapshot (trunk):     
https://bugs.php.net/fix.php?id=63990&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=63990&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=63990&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=63990&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=63990&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=63990&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=63990&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=63990&r=notwrong
Not enough info:            
https://bugs.php.net/fix.php?id=63990&r=notenoughinfo
Submitted twice:            
https://bugs.php.net/fix.php?id=63990&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=63990&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=63990&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=63990&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=63990&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=63990&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=63990&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=63990&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=63990&r=mysqlcfg

Reply via email to