Posted by Jon Slaughter on 06/07/07 15:27
"Toby A Inkster" <usenet200705@tobyinkster.co.uk> wrote in message
news:uunkj4-h76.ln1@ophelia.g5n.co.uk...
> Edward Z. Yang wrote:
>
>> class TestFunction
>> {
>> var $probability = 0.234321;
>> function call() { /* ... */ }
>> }
>>
>> $func = new TestFunction();
>> $func->call();
>
> The other possibility is to use a static variable and function. The
> example below is PHP5 code -- I have no idea if it's possible to translate
> it to PHP4.
>
> class Test
> {
> public static $probability = 0.234321;
>
> public static function call()
> {
> $x = self::$probability * 1000000;
> $r = rand(0, 1000000);
> return ($r<$x);
> }
> }
>
> // Using the function
> $truth = Test::call();
>
> // Retrieving the "attribute"
> $prob = Test::$probability;
>
So I have to call the function first? ;/ Isn't going to work ;/ I have to
get the probabilities from the function to determine which function to call
;/
Ultimately it seems I'm going to have to use functors or just write a method
to add the functions that takes a pointer but just seems a little overkill
just to add one "attribute".
thanks,
Jon
[Back to original message]
|