ole wrote:You do with a class as well...? Unless your referring to your IDE's code insight feature, but surely that's a problem with the IDE, not PHP.
You can refer to the prototype:
Code: Select all
public function __construct($age, $weight, $cuteNess)
As for the typos, you should always code with warnings on, then you'll get notices if $array['bob'] doesn't exist.
does this produce a warning?
Code: Select all
$array = array();
$array['bob'] = 1;
" you should always code with warnings on" What's that supposed to mean? If I code with notices on, you can bet your right sock that I've got warnings on. Only an idiot would code with warnings off.
Code: Select all
$array = array();
$x = $array['bob'];
Creates a notice, as does:
Code: Select all
$obj = new Rabbit();
$x = $obj->bob;
So I don't see how your typo argument is valid.
Also, arrays have a lot more tools for manipulation. It's what they were designed for. It's a lot harder to search through an object for a variable's value. As for the constructor argument, you're making things extremely hard for yourself in terms of flexibility by having to predefine all your variables. Perhaps it would make more sense to spend those few seconds double checking you've spelled it correctly.
Apart from possible scalability (but you should have your software planned out and decide whether you'll need to extend the class in the first place) your only other reasonings are to prevent your bad mistakes. I don't see that as a valid reason of using a class. It's like using a table for layouts in HTML - unnecessary, slower, poor standards, and more footprint.