ID:          9777
 Comment by:  php at thekid dot de
 Reported By: yohgaki at dd dot iij4u dot or dot jp
 Status:      Open
 Bug Type:    Feature/Change Request
 PHP Version: 4.0.4pl1
 Assigned To: yohgaki
 New Comment:

Parts of this have been realized with type hints in PHP5.


Previous Comments:
------------------------------------------------------------------------

[2001-03-16 00:53:13] yohgaki at dd dot iij4u dot or dot jp

I think it would be nice to have function/class prototype only for
while developing PHP application. (I guess developers are already come
up with similar/better idea for it, though)

With prototype, compiler may issue error with invalid parameter or
invalid use of function/class and PHP may warn if use of function/class
does not match with prototypes at run time.

Such as:
   void function do_something(integer(min, max), resource('file'),
array(text,integer), &object('object_name') = null);
   // Such syntax that specifying expected parameters' range/contents
may not a good idea, though.
   // The same thing can be done with assert() anyway.
   // It might be good idea enabling assert() in prototype definition.
   // to specify parameters range/contents to get rid of many assert()
   // from function itself. like

   void function($int integer) {
       assert($int > 0);
   }

   // Checking parameter types can be done by assert(). But, it's nice
   // to have prototypes.

   class foo {
        public var pub_var;
        private var priv_var;

        public object foo(integer); 
        protected integer bar(array);
        private void internal_use_only();
   }

and include prototypes with special include statement like

   include_prototype('filename'); // development only prototypes
   require_prototype('filename'); // required prototypes

and have a new php.ini entry for prototype

   prototype.enable = true; // to disable include_prototype

like assert().

Currently, PHP function may take any types for a parameter, even if
function accepts certain types. This may result in unwanted behaviors
as I submitted a foreach bug. (foreach seems to behave really wrong
way, if parameter is not an array.)

Additionally, if prototype may specify function will not return value,
parser can prevent programmers to use implicitly returned NULL value as
RVALUE.

PHP needs to do additional work for Parse/Compile/Execute with
prototypes, but it would be acceptable while developing PHP
application. It would be nice to have a ability that programmer can get
rid of prototypes for better performance, once she/he is confident with
his/her codes.
(Inexperience programmers may write code that is not secure w/o
prototypes. But they write insecure code w/ or w/o prototypes anyway)



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=9777&edit=1

Reply via email to