Can I do this in php5?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ming

    Can I do this in php5?

    private fields declaration like Java

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

    private XML_RPC_Client $Client;

    I know I can do

    private $Client;

    Thanks,

  • Jerry Stuckle

    #2
    Re: Can I do this in php5?

    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.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • Mike P2

      #3
      Re: Can I do this in php5?

      On May 16, 1:28 pm, Ming <minghu...@gmai l.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

      Comment

      • ZeldorBlat

        #4
        Re: Can I do this in php5?

        On May 16, 1:28 pm, Ming <minghu...@gmai l.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.t ypehinting.php>

        Comment

        • Ming

          #5
          Re: Can I do this in php5?

          Many thanks to all of you :)

          Comment

          Working...