Page Chapter 20. Writing Secure Code, Page 310

Location on the page: 
Code example below 3rd paragraph
Error: 

if (!in_array($type, node_get_types())) {

Correction: 

if (!in_array($type, array_values(node_get_types()))) {

Description of the Error: 

The php function in_array() will not work the way it is written in the book. The php function checks the values of the array returned by node_get_types() and not the keys, which are what holds that names of the content types in the array returned from node_get_types(). The values of the arrays from node_get_types() are objects. The test suggested in the book will always fail unless you only get the keys, as suggested in the code correction I've submitted.

[The correction is incorrect. We should be getting the keys for comparison, not the values. It should probably be if (!in_array($type, array_keys(node_get_types('name')))) { ... } We would use the 'name' parameter to node_get_types() to avoid returning objects that we will just throw away; 'name' gets us just the internal node type name and its friendly name. -JV]