Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to explicitly declare the type of a member var in a php class

Tags:

php

If I can explicitly declare the type of a member var (esp. other class as a member), them my IDE( such as Dreamweaver) can know the member's member.

class PHPClass(){
    OtherClass $member_var;
}
like image 985
lovespring Avatar asked Apr 30 '12 13:04

lovespring


2 Answers

You can't do that in PHP but you can come close by using type hinting:

class PHPClass
{
    protected $member_var;

    public function __construct(OtherClass $member)
    {
        $this->member_var = $member;
    }
}

I don't know if that will help you in Dreamweaver, though.

like image 195
John Conde Avatar answered Sep 25 '22 01:09

John Conde


The only way is to use documentation like so:

class MyClass {

    /**
     * @var OtherClass This is my other class
     */
    private $other;

}
like image 32
Petah Avatar answered Sep 24 '22 01:09

Petah