View Full Version : What exactly is PHP5 Strict?

02-25-2010, 05:33 PM

Can anyone help me by pointing me to a site that explains simply what the differences are bewtween PHP5 Strict and non strict? I am aware of declaring variables and using <?php instead of <php but I suspect there is more to it.

An online validator with descriptive error messages would be good. ;)


02-25-2010, 07:00 PM
Sorry I meant

"<?php instead of <?"


02-25-2010, 07:05 PM
E_STRICT will attempt to notify you of any code usage that 'works' but may not work in the future. Unlike deprecated errors that tell you to stop using a particular type of function or signature, E_STRICT will instead inform you that what you're doing works - currently - but is expected to change in the future (and may not work with previous versions properly).

The only example I can think of off the top of my head is the usage of static scoping in classes in php:

class MyClass
public function testFunc()
return __METHOD__;

$method = MyClass::testFunc();
print $method;

If you've explicitly included E_STRICT (using error_reporting(E_STRICT); or error_reporting(E_ALL | E_STRICT); for examples), it should indicate that testFunc should not be called statically from MyClass since its declared as an object method and not a class method (the signature itself is missing the static keyword). This example should work though since the actual method doesn't attempt to use the '$this' context to implicitly indicate an object method.

Does that help you?

BTW, noticed you snuck in there ;)
I figured you meant ths short tags, though it should be mentioned that php will interpret <script language="php"> as valid identifiers. I've never, not once, used that though.
Also, things that they plan on actually removing (like allowing call by reference runtime passing) will trigger an E_DEPRECATED notice to tell you to stop using them (they will be gone in php6). The same will apply if they add short open tags to the list (currently I believe it is not on the list).

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum