php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48444 Passing wrong variable content to class
Submitted: 2009-06-01 12:14 UTC Modified: 2009-06-01 12:47 UTC
From: oliver dot ridgway at trafford dot ac dot uk Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.2.9 OS: Windows XP
Private report: No CVE-ID: None
 [2009-06-01 12:14 UTC] oliver dot ridgway at trafford dot ac dot uk
Description:
------------
I can't work out if this a bug or php is working differently than I expected, so i thought I'd report it just in case.
$var1 is not 0 so why is the if statement saying it is?

Reproduce code:
---------------
<?php
class test {
	function __construct($var1) {
		print($var1 . " ");
		if($var1 == 0) {
			print('zero');
		}
		if($var1 != 0) {
			print('not');
		}
	}
}
$test = new test('string');
?>

Expected result:
----------------
string not

Actual result:
--------------
string zero

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-06-01 12:47 UTC] jani@php.net
# php -r 'var_dump("string" == 0);'
bool(true)
# php -r 'var_dump("string" != 0);'
bool(false)

# php -r 'var_dump("string" === 0);'
bool(false)
# php -r 'var_dump("string" !== 0);'
bool(true)

RTFM: http://www.php.net/manual/en/language.operators.comparison.php
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Dec 04 10:00:01 2025 UTC