views:

65

answers:

1

How can this

<?php
assert( 1.0 < 2.0 );
?>

result in

Warning: assert() [function.assert]: Assertion failed in C:\Program Files (x86)\wamp\www\test.php on line 2

Edit: depending on the file I put this code in, 1.0 < 2.0 evaluates to false or true.

+2  A: 

Try writing it as a string instead. :)

assert("1.0 < 2.0");

Ace
like in `assert( "hello world" )`? The thing is, actually the condition `1.0 < 2.0` returns false.
xtofl
The string you pass to assert is parsed and executed as a php code and then the result is asserted. This is written here: http://php.net/manual/en/function.assert.php
Max
`assert()` will evaluate the string you pass it. Generally passing a string is better practice; assert can show you the test that failed, and when assert checking is off the code isn't evaluated saving some overhead in production.
meagar
thaks for the quote-tip. It's very useful.
xtofl