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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: rok at andree dot si
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 16 21:01:33 2025 UTC