Reputation: 131
For example, if I have
assert('2<1');
It turns out that the assertion returns as true. I also copy pasted Example #2 from http://php.net/manual/en/function.assert.php and it also evaluated every single assertion as true, when that's clearly not the case. Any idea what might be causing this?
Edit -
<?php
var_dump(assert('2<1'));
?>
Output is
true
If i run this at http://sandbox.onlinephpfunctions.com/, the assertion fails as expected. Yet this does not happen on my test server.
Edit #2 - PHP Version:
PHP 7.0.9-1+deb.sury.org~trusty+1 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.9-1+deb.sury.org~trusty+1, Copyright (c) 1999-2016, by Zend Technologies
Upvotes: 5
Views: 705
Reputation: 4187
Assert's have 3 settings:
(exert from php.ini):
-1: Do not compile at all
0: Jump over assertion at run-time
1: Execute assertions
...
http://php.net/zend.assertions
-1 being "production", 1 being development and zero being an odd middle-ground that appears to act like production.
Apparently when in non-development mode this means that assert will always return true, effectively bypassing the check.
Upvotes: 5