Re: Variable Functions?

From: Date: Tue, 05 Nov 2002 12:17:31 +0000
Subject: Re: Variable Functions?
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-90502@lists.php.net to get a copy of this message
Is this really needed? -- Maxim Maletsky maxim@php.net www.PHPBeginner.com // PHP for Beginners www.maxim.cx // my Home // my Wish List: ( Get me something! ) http://www.amazon.com/exec/obidos/registry/2IXE7SMI5EDI3 "Dan Hardiker" <dhardiker@staff.firstcreative.net> wrote... : > Hi All, > > Just a thought, but while working reciently with a few ECMA scripting > languages (eg: ActionScript in Flash MX), I uncovered the amazing uses > (especially from a security point of view) of variable functions. > > For those that dont know, it allows you to assign a function to a > variable, rather than to declare it globally, for example: > > <?php > > function test ($param, $default=false) { > // stuff goes here > } > test("my param"); > > /* could also be written as */ > > $func_test = function ($param, $default) { > // stuff goes here > } > $func_test("my param", true); > > /* removing a function could then be */ > > unset($func_test); > > ?> > > Any form of variable or constant would be able to be used (eg: a function > inside of an array, or a class method as a property). This would allow the > very very simple usage of "getter-setters", as they are called in flash. > > EG: You may have the properties $user->birthdate and $user->age, where you > want the age to be pulled dynamically. At the moment you have to define > $user->age(), but the following code could be used: > > <?php > > class user { > var $birthdate = "YYMMDDHH"; > var $age = function { > // Code to get birthdate > $myAge = // .... // ; > // Return the age > return $myAge; > } > } > > ?> > > This may or may not fit into the way PHP is going, but its just an idea - > and ideas have never been frowned upon, (nor should they be!) > > I think that puts across the general gist of my suggestion... any thoughts > or comments on the idea? > > > -- > Dan Hardiker [dhardiker@staff.firstcreative.net] > ADAM Software & Systems Engineer > First Creative > > > > -- > PHP Development Mailing List <http://www.php.net/> > To unsubscribe, visit: http://www.php.net/unsub.php >

« previous php.dev (#90502) next »