Reply to Re: function "attributes"

Your name:

Reply:


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/

[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

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