Posted by Toby A Inkster on 06/07/07 07:16
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;
--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 103 days, 14:54.]
URLs in demiblog
http://tobyinkster.co.uk/blog/2007/05/31/demiblog-urls/
Navigation:
[Reply to this message]
|