php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #13724 assert does not work as documented
Submitted: 2001-10-17 23:46 UTC Modified: 2001-11-24 21:35 UTC
From: yasuo_ohgaki at yahoo dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.1.0RC1 OS: linux 2.4.4/glibc 2.2.2
Private report: No CVE-ID: None
 [2001-10-17 23:46 UTC] yasuo_ohgaki at yahoo dot com
According to the manual, assert() accepts string or boolean. However, it seems assert() does handle string type well, especially if it's a class property. (Parse error) Either PHP or the manual page is wrong.

Following code does not work well.

== code #1 ==
<?php
class A 
{
	var $name = 'class A';

	function print_name() 
	{
		assert($this->name);
		print $this->name;
	}
	
}
$obj1 = new A;
$obj1->print_name();
?>== result #1 ==
Parse error: parse error in /home/yohgaki/public_html/test/bug/obj_property/test.php(7) : assert code on line 1

Fatal error: Failure evaluating code: class A in /home/yohgaki/public_html/test/bug/obj_property/test.php on line 7

== code #2 ==
<?php 
$str1 = '';
$str2 = 'abc';

assert($str1);
assert($str2);
?>
== result #2 ==Warning: Assertion "" failed in /home/yohgaki/public_html/test/bug/obj_property/test2.php on line 5

Warning: Use of undefined constant abc - assumed 'abc' in /home/yohgaki/public_html/test/bug/obj_property/test2.php(6) : assert code on line 1

== code #3 ==
<?php 
$arr = array('abc');

assert($arr['abc']);
?>
== result #3 ==
Warning: Undefined index: abc in /home/yohgaki/public_html/test/bug/obj_property/test3.php on line 4

Warning: Assertion failed in /home/yohgaki/public_html/test/bug/obj_property/test3.php on line 4

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-10-18 00:05 UTC] yasuo_ohgaki at yahoo dot com
I've take a look at assert.c. 
assert() expects string to eval. So I guess if it doesn't work with object property, it would be okay. 

Document does not explain string must be a valid PHP code, so I changed this report to documentation problem.
 [2001-11-24 16:09 UTC] georg@php.net
assert needs a parameter, which will be evaluated as PHP code, as described in the manual:

"assert() will check the given assertion and take appropriate action if its result is FALSE. 

If the assertion is given as a string it will be evaluated as PHP code by assert(). "

I don't know what should be wrong in the documentation.

Georg
 [2001-11-24 21:35 UTC] yasuo_ohgaki at yahoo dot com
It looks document is updated. Closed.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 07 09:01:33 2025 UTC