|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76710 result of empty() is not correct
Submitted: 2018-08-06 08:50 UTC Modified: 2018-08-06 08:56 UTC
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: mehdimn dot mail at gmail dot com Assigned:
Status: Not a bug Package: Variables related
PHP Version: 7.2.8 OS: linux ubuntu
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
32 - 21 = ?
Subscribe to this entry?

 [2018-08-06 08:50 UTC] mehdimn dot mail at gmail dot com
The result of empty($objA->g) is TRUE but result of var_dump or echo the $objA->g is a string value.

Maybe help you to fix it, I found :

Test script:
# test empty result
class A {
	private $g = '';

	public function __get($property) {
		return $this->$property;
	function run() {
		$this->g = '4, 5, 6';

	function callA() {
		$clsB = new B();

class B {
	function callB($objA) {
		echo '<pre>';
		var_dump($objA->g); // is not empty
		var_dump(empty($objA->g)); // result is TRUE !? 
		echo '</pre>';

$a = new A();

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-08-06 08:56 UTC]
-Status: Open +Status: Not a bug
 [2018-08-06 08:56 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at
> Note:
> When using empty() on inaccessible object properties, the __isset() overloading method will be called, if
> declared.

You need to implement __isset.

In general, __get, __set, and __isset must all be implemented together for properties to work correctly.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed May 29 09:01:33 2024 UTC