Tuesday, June 17, 2008

50 Random PHP5 Facts

Here's a list of 50 49 random facts about PHP.

  1. You MUST load PDO before loading any PDO drivers
  2. An iterator cannot be used with foreach by reference
  3. Cannot create references to elements of a temporary array expression
  4. Cannot create references to/from string offsets nor overloaded objects
  5. Cannot assign by reference to overloaded objects
  6. Only variable references should be returned by reference
  7. Only variables can be passed by reference
  8. Cannot return string offsets by reference
  9. Cannot use string offset as an array
  10. Cannot use object as array -- See Dans comment
  11. Cannot use a NULL value as an array
  12. Cannot use a scalar value as an array
  13. foreach() can not iterate over objects without PHP class
  14. Cannot use assign-op operators with overloaded objects nor string offsets
  15. __HALT_COMPILER() can only be used from the outermost scope
  16. Assigning the return value of new by reference is deprecated
  17. Variables passed to each() must be an array or object
  18. Constants may only evaluate to scalar values
  19. is_a() is deprecated. The "instanceof" operator should be used instead This has changed as of PHP 5.3, see Gregs comment
  20. Cannot add internal functions to return value from get_defined_functions()
  21. Cannot add user functions to return value from get_defined_functions()
  22. Static functions cannot be abstract
  23. Exceptions must be derived from the Exception base class
  24. Need to supply an object when throwing an exception
  25. Cannot declare self-referencing constants
  26. Cannot use call_user_function on objects without a class entry
  27. Cannot access self:: when no class scope is active
  28. Cannot access parent:: when no class scope is active
  29. Cannot access parent:: when current class scope has no parent
  30. add_assoc_function() is no longer supported
  31. Usage of {} to access string offsets is deprecated and will be removed in PHP 6
  32. Cannot re-assign $this
  33. __toString() must not throw an exception
  34. Can't use method return value in write context
  35. Can't use function return value in write context
  36. Multiple access type modifiers are not allowed
  37. Cannot use the final modifier on an abstract class member
  38. Default value for parameters with a class type hint can only be NULL
  39. Default value for parameters with array type hint can only be an array or NULL
  40. Cannot call __clone() method on objects - 'clone $obj' should be used instead
  41. Clone method does not require arguments
  42. Interfaces cannot not implement themselves
  43. Classes may not inherit from classes declared final
  44. Classes cannot inherit previously-inherited constants from interfaces
  45. Classes cannot implement previously-implemented interfaces
  46. Class declarations may not be nested
  47. Cannot use reserved words as class or interface names
  48. Interfaces may not include member variables
  49. Properties cannot be declared abstract
  50. Cannot declare properties final, the final modifier is allowed only for methods

6 comments:

DanN said...

I disagree with 10.

Example code provided:

Code

Tobiasz Cudnik said...

Good wrap-up. Thanks.

Anonymous said...

51. PHP Cannot be used to write nice code.

Greg Wright said...

Ironically Re: 19 is_a is undeprecated in 5.3 so for now it just throws annoying notices.

Greg Wright said...

#33 __toString can not throw an exception is mindless and messing up my life at the moment.

As is the inability to have methods with the same name but different signatures. PHP is a toy but some of us have no choice.

Joe Kovar said...

I have to agree. I can't think of a reason other than someone not wanting to change something under the hood that being able to use exceptions within __toString shouldn't be allowed.