I’m just getting into OOP with php and discovered almost by accident that if I put the object type before the name in the function definition that the IDE I’m using can resolve member functions and data members for the object.
For example:
public function foo(car $car)
{
}
As opposed to:
public function foo($car)
{
}
Is the first method legitimate and preferred?
Thanks for helping a noob 🙂
Definitely: Type Hinting. Thats a feature of PHP itself and the IDE just makes you a favour with giving you more useful code completion. Try it out and pass an object of the wrong type. This will help you to find bugs, that result from wrong types passed to methods, much earlier.
Also you should have a look at doccomments (sorry, no link). Most IDEs are able to read and use them for additional code completion suggestions too.