php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #18526 assertion fails
Submitted: 2002-07-24 02:58 UTC Modified: 2002-09-11 14:05 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: horny at mail dot az Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 4.2.1 OS: Windows XP
Private report: No CVE-ID: None
 [2002-07-24 02:58 UTC] horny at mail dot az
<?php
	assert_options(ASSERT_ACTIVE, '1');
	assert_options(ASSERT_WARNING, '1');
	assert_options(ASSERT_QUIET_EVAL, '0');

	$AVAILABLE_LANGS = array('az' => 'az', 'ru' => 'ru', 'en' => 'en'); # as per RFC 1766

	function func($predicate)
	{
		do {
			$freeflag = null;
			if (call_user_func($predicate, $freeflag) === FALSE)
				break;
			assert('!is_null($freeflag)');
		} while (0);
	}

	class foo
	{
		function foo_method(&$freeflag)
		{
			$retval = (bool) rand() % 2;
			if ($retval)
				$freeflag = 1;

			return $retval;
		}
	}

	$foo_instance = new foo;
	func(array($foo_instance, 'foo_method'));
?>

D:\>c:\php\php-cli haha.php

Warning: Assertion "!is_null($freeflag)" failed in haha.php on line 14

It occurs *always* no matter what foo_method() returns, as if asserts() are happening asynchronously.

If I instead change func() to
	function func($predicate)
	{
		$freeflag = null;
		if (call_user_func($predicate, $freeflag) === TRUE)
		    assert('!is_null($freeflag)');
	}

The assertion doesn't fail. (because it's NOTREACHED?)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-07-30 01:16 UTC] horny at mail dot az
This is my bug.
$retval = (bool) rand() % 2;
should of course be
$retval = (bool) (rand() % 2);

But in the real code (off of which I made up this example) the assertion still fails mysteriously...
 [2002-09-11 14:05 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

!is_null($freeflag) returns FALSE, which is why your assertaion is returning a warning.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jun 29 15:01:30 2024 UTC