Ganesh Yoganand
Ganesh Yoganand

Reputation: 153

CakePHP 2.1 Hash vs Set

I am new to CakePhp, the documentation of CakePHP core libraries subsection utilities speaks about the hash and set for the better usage of arrays. Can any one help me knowing what are the relevant situations we should use hash and what are the relevant situations we should use set.

Upvotes: 2

Views: 739

Answers (1)

penguin egg
penguin egg

Reputation: 1194

If you compare the functions of the two classes, many of them have similar functionality. They are used for mostly array manipulation and offer some handy ways to extract data from typical "Cake" arrays (make sure to check out Hash::extract or Set::extract).

Hash was not introduced until CakePHP 2.2. Set on the other hand has been around since the CakePHP 1.x days.

So in CakePHP 2.1, you will be using Set. In CakePHP 2.2, Set is deprecated so you should probably use Hash for better chances of future compatibility.

See http://book.cakephp.org/2.0/en/core-utility-libraries/hash.html and http://book.cakephp.org/2.0/en/core-utility-libraries/set.html.

Quoted from the Cake API ( http://api22.cakephp.org/class/hash ):

Hash provides an improved interface, more consistent and predictable set of features over Set. While it lacks the spotty support for pseudo Xpath, its more fully featured dot notation provides similar features in a more consistent implementation.

Upvotes: 5

Related Questions