PHP objects and their functions

I am using PHP 5 now and I am struggling to use OOP in PHP 5. I am having a problem. I had several classes and several functions inside them. Few functions require passing arguments, which are objects of the classes that I wrote myself. I did not notice strictly arguments. Is there a way to make it strongly typed so that I can use Intellisense at compile time?

Example:

class Test { public $IsTested; public function Testify($test) { //I can access like $test->$IsTested but this is what not IDE getting it //I would love to type $test-> only and IDE will list me available options including $IsTested } } 
+4
source share
3 answers

Well, you can use the hinting type to do what you want:

 public function Testify(Test $test) { } 

Either this or the dock block:

 /** * @param Test $test The test to run */ 

It depends on the IDE and how it chooses type hints ... I know that NetBeans is smart enough to pick up a hint like Testify(Test $test) and let you go from there, but some other IDEs are not that smart ... So it really depends on your IDE, the answer to which will give you autocomplete ...

+3
source

I was going to give a simple no. answer, then found a section in Type Hinting in PHP docs.

I think that answers.

 <?php class Test { public $IsTested; public function Testify(Test $test) { // Testify can now only be called with an object of type Test } } 

I'm not sure what Intellisense knows about the type of hint. It all depends.

+1
source

$test not a class variable. Maybe you want $this ?

 $this->IsTested; 

OR

 public function Testify(Test $test) { $test->IsTested; } 
+1
source

All Articles