Errata (First Edition)

This page lists the errors found in the first edition of the book.

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]

Chapter 20. Writing Secure Code, Page 311

Location on the page: 
Code snippet at top
Error: 

$titles array_map($titles, 'check_plain');

Correction: 

$titles = array_map('check_plain', $titles);

Description of the Error: 

Parameters for array_map() are reversed.

Chapter 20. Writing Secure Code, Page 314

Location on the page: 
code listing
Error: 

no definition of $num

Correction: 

$num = 10; (or something)

Description of the Error: 

there is no definition of the $num variable

Chapter 22. Optimizing Drupal, Page 354

Location on the page: 
5th paragraph, end of "Beyond a Single File System"
Error: 

http://drupal.org/project/filesystem currently goes to "Page not found"

Correction: 

Not sure, as this probably worked when the book was written. Right now the closest approximate is:

http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/filesystem/

Description of the Error: 

Broken link.

Chapter 23. Installation Profiles, Page 360

Location on the page: 
Middle of page, in function univirsity_profile_modules() example code
Error: 

'help' module is listed both under "// Enable required core modules" (we assume this line is necessary) and "// Enable optional core modules"

Correction: 

According to the Drupal 5.1 modules administration page, help is an optional core module.

The list under "// Enable required core modules" should now read:
'block', 'filter', 'node', 'system', 'user', 'watchdog',

Description of the Error: 

typo or copy-paste type of error

Chapter 23. Installation Profiles, Page 362

Location on the page: 
Last chunk of code example
Error: 

Use of t() instead of st()

(Contrary to note on page 363, "We use st() instead of t() throughout the installation profile to allow the entire installation profile translation, if any, to be stored in an installation profile translation file.")

Correction: 

Replace:
'name' => t('News Categories'),
with:
'name' => st('News Categories'),

Description of the Error: 

typo