|
|
| Jean Pierre Daviau 2006-03-17, 6:56 pm |
| Hi gurus,
I did some Java and I am inquiri8ng about something 'like' a satic main
method in PHP5.
Itried the following which works:
class Counter {
public static $edible = 0;
public static $count = 3;
function __construct( $edible ) {
$this->edible = $edible;
return $edible;
}
function __destruct() {
self::$count--;
}
static function getCount() {
return "in Get Count\n";
}
}
print(Counter::getCount(). "\n");
--
Thanks for your attention.
Jean Pierre Daviau
--
Easyphp1.8
Apache1.3.24
DEVC++, borland 5.5
windows Xp
asus p4 s533/333/133
Intel(R) Celeron (R) CPU 2.00 GHz
http://www.jeanpierredaviau.com
| |
| Jean Pierre Daviau 2006-03-17, 6:56 pm |
| One other thing. Is ther a way to call it directly trhough a comand line:
php myclass.php parameter1 parameter2
etc
| |
| Johannes Wienke 2006-03-17, 6:56 pm |
| Am 17.03.2006 20:15 schrieb Jean Pierre Daviau:
> One other thing. Is ther a way to call it directly trhough a comand line:
> php myclass.php parameter1 parameter2
That wouldn't make any sense. As a websites-user you can't access any
comand-line. You have to wrap the Request-String
mypage.php¶m1=foo¶m2=bar
php:
myfunction($_REQUEST['param1'], $_REQUEST['param2']);
| |
| Johannes Wienke 2006-03-17, 6:56 pm |
| Am 17.03.2006 18:04 schrieb Jean Pierre Daviau:
> Hi gurus,
> I did some Java and I am inquiri8ng about something 'like' a satic main
> method in PHP5.
You can make every function to something like the main-method bei
executing it in your script, because the basic concept of PHP is not
strict OOP.
> Itried the following which works:
>
> class Counter {
> public static $edible = 0;
> public static $count = 3;
> function __construct( $edible ) {
> $this->edible = $edible;
> return $edible;
> }
> function __destruct() {
> self::$count--;
> }
>
> static function getCount() {
> return "in Get Count\n";
> }
> }
>
> print(Counter::getCount(). "\n");
That's the way to do so...
| |
| Jean Pierre Daviau 2006-03-17, 6:56 pm |
|
> That wouldn't make any sense. As a websites-user you can't access any
> comand-line. You have to wrap the Request-String
I forgot to precise I am using php command line capabilities here.
| |
|
| On Fri, 17 Mar 2006 14:15:11 -0500, "Jean Pierre Daviau"
<Once@WasEno.ugh> wrote:
>One other thing. Is ther a way to call it directly trhough a comand line:
>php myclass.php parameter1 parameter2
Yes, you can access $argc (an integer) and $argv (an array) when using
the CLI. These variables operate mostly like their C counterparts.
<?php
echo 'Argument count is ' . $argc . "\n";
$count = 0;
foreach($argv as $param) {
echo 'Parameter ' . $count++ . ' is ' . $param . "\n";
}
?>
$ php foo.php arg1 param2 foo
Argument count is 4
Parameter 0 is test.php
Parameter 1 is arg1
Parameter 2 is param2
Parameter 3 is foo
hth
--
<s@guerril.la.ape> (to email, remove .ape)
Apologies for the ad below.
--
*** Free account sponsored by SecureIX.com ***
*** Encrypt your Internet usage with a free VPN account from http://www.SecureIX.com ***
|
|
|
|