By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 1,261 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

Can I do this in php5?

P: n/a
private fields declaration like Java

require 'XML/RPC.php';
....

private XML_RPC_Client $Client;

I know I can do

private $Client;

Thanks,

May 16 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Ming wrote:
private fields declaration like Java

require 'XML/RPC.php';
...

private XML_RPC_Client $Client;

I know I can do

private $Client;

Thanks,
No. PHP is untyped; $Client can be anything. Just assign a new
XML_RPC_Client to $Client in your constructor.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
May 16 '07 #2

P: n/a
On May 16, 1:28 pm, Ming <minghu...@gmail.comwrote:
private fields declaration like Java

require 'XML/RPC.php';
...

private XML_RPC_Client $Client;

I know I can do

private $Client;

Thanks,
You cannot do it exactly the same as in Java, but you don't really
need to worry about doing that in PHP. If you want, you can initialize
it with "$Client = new XML_RPC_Client();" but that's unnecessary. You
might as well just do "private $Client;" to make the field and then
"$Client = new XML_RPC_Client();" in a method. If you are concerned
because you are taking the object as an argument and setting $Client
to that, you can be selective with your arguments (in PHP5+) like:

public function setClient( XML_RPC_Client $argClient )
{
$this->Client = $argClient;
}

Note that you don't need to use =& in PHP5.

-Mike PII

May 16 '07 #3

P: n/a
On May 16, 1:28 pm, Ming <minghu...@gmail.comwrote:
private fields declaration like Java

require 'XML/RPC.php';
...

private XML_RPC_Client $Client;

I know I can do

private $Client;

Thanks,
Not in that context. Besides, why would you want to? Don't you trust
yourself to put the right thing in there? :)

Having said that, PHP allows you to specify the class of an argument
to a function. See this:

<http://www.php.net/manual/en/language.oop5.typehinting.php>

May 16 '07 #4

P: n/a
Many thanks to all of you :)

May 17 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.