On Thu, 2013-10-17 at 08:25 +0100, Joe Watkins wrote:
Morning All,
I'd like to draw some attention to how poor assertions are in PHP.
The current assertion API is not usable in my opinion; it has a
considerable overhead, relies on eval(), and is generally poorly
implemented.
I don't have a strong opinion on this, but mind that by being based on
eval the assert expression can use features from a different version of
PHP. Something like
if (PHP_VERSION_ID >= 50300) {
assert('foo\\bar::baz == 42');
}
the new form
if (PHP_VERSION_ID >= 50300) {
assert foo\\bar::baz == 42;
}
would give a parse error on older versions.
(Yes, I'm using 5.3 and <5.3 as example where the new form would fail
anyways, feel free to use PHP_VERSION_ID >= 51200 and PHP 5.26.0
features)
This means that assert("some code here") will pass assertion
causing no error, because strings are no longer treated as code,
because eval is evil();
I think this is bad for migration of code. For one it is impossible to
have a code base with asserts working in both versions. For two it
silently leads to completely different behavior. Changing this needs
some clever strategy allowing migration.
johannes
Okay, so if the expression used is a string, it is now evaluated, this provides some backward compatibility and the possibility to avoid compilation of the expression at compile time...
Better ??
Cheers
Joe