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