003.txt 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. Title: Loose type requirements for functions
  2. Version: $Id$
  3. Status: draft
  4. Maintainer: Brian Moon <brianm@dealnews.com>
  5. Created: 2001-09-17
  6. Modified: 2001-09-17
  7. 1. Background/Need
  8. ==================
  9. Many internal functions of PHP will reject parameters because of their
  10. type (the array and variable function come to mind). For userland
  11. this is not an easy task as there is no uniform way to do it. An
  12. addition to the engine for requiring loose types would allow
  13. developers to know that the data passed to their functions are of the
  14. correct type and reduce the need for duplicating the same code in
  15. every function to check for the type of data.
  16. 2. Overview
  17. ===========
  18. Loose typing mostly means evaluating the contents of the variable and
  19. not the type of the variable itself. The requirements for this would
  20. and should work much like several of the is_* functions do now.
  21. The typing of parameters would be optional and those not typed would
  22. simply continue to be treated as they are now.
  23. 3. Functionality
  24. ================
  25. 3.1. Allowed Types
  26. ==================
  27. Only loose types should be needed to ensure the data is usable by the
  28. function. Duplicating the functionallity of is_scalar, is_resource,
  29. is_array and is_object should give developers all the information they
  30. need to use a variable correctly.
  31. 3.2. Syntax
  32. ===========
  33. The current function syntax should be expanded to allow typing of
  34. variables inline in a C style.
  35. function foo ($var){
  36. }
  37. could be changed to require an array such as:
  38. function foo (array $var){
  39. }
  40. 3.3. Errors
  41. ===========
  42. Mis-matches in type should be reported as fatal errors and should halt
  43. the execution of a script as that function cannot be run and code
  44. following could not reliably run.
  45. 4. Compatibility Notes
  46. ======================
  47. Old code that does not take advantage of this will run without
  48. modifications.