You are here: Re: function "attributes" « PHP Programming Language « IT news, forums, messages
Re: function "attributes"

Posted by Norman Peelman on 06/08/07 00:40

Jon Slaughter wrote:
> is there any way to simply add an attribute like feature to a
> function/method definition?
>
> say I create a function like
>
> function Test()
> {
>
> //....
> }
>
> but I want to assign a probability to it in the definition itself... maybe
> something like
>
> function Test()
> {
> static $probability = 0.234321;
> //....
> }
>
> Now is there any way that I can get the probability from the function? I'm
> using function pointers to call the functions in a random way. Essentially
> having a list of functions that have assigned probabilities and calling them
> based on that probability(I don't want to really seperate the probability
> from the definition.
>
>
> Ultimately it would be nice to extend the syntax to handle a new keyword
> like
>
> function Test():[Probability=0.123421]
> {
>
> }
>
> or something like that but I know thats not going to happen.
>
> Thanks,
> Jon
>
>

Ok, this is ugly but if you name your functions by their probability:

function _0_234321()
{ // test function
$probability = 0.234321;
echo "$probability<br>";
...
}
$probability = 0.234321;
$func_to_call = '_'.str_replace('.','_',$probability);
//echo $func_to_call.'<br>';
call_user_func($func_to_call);

.... or am I missing the point?

Norm

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация