php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63990 Function returns wrong when deailing with class magic methods
Submitted: 2013-01-15 12:27 UTC Modified: 2013-01-15 13:22 UTC
From: rok at andree dot si Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3Git-2013-01-15 (snap) OS: Linux
Private report: No CVE-ID: None
 [2013-01-15 12:27 UTC] 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) 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-01-15 13:22 UTC] johannes@php.net
isset() and empty() call the __isset() magic method, not __get.
 [2013-01-15 13:22 UTC] johannes@php.net
-Status: Open +Status: Not a bug
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 03 19:01:32 2024 UTC