Reply to Re: function "attributes"

Your name:

Reply:


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]


Удаленная работа для программистов  •  Как заработать на 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

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