This is a list of the 100 most common built-in PHP functions, and the 100 most common Drupal functions in the Drupal source code. Language constructs and reserved words are excluded from the count (foreach, for, while, list, isset, etc).
Total Built-in Functions Used: 239
Total Built-in Function calls in Drupal source code: 1392.
| Rank | Function | Occurrences | Per Cent |
|---|
| 1 | define | 94 | 6.75 |
| 2 | implode | 79 | 5.68 |
| 3 | array_merge | 63 | 4.53 |
| 4 | substr | 58 | 4.17 |
| 5 | trim | 38 | 2.73 |
| 6 | str_replace | 38 | 2.73 |
| 7 | count | 37 | 2.66 |
| 8 | preg_replace | 35 | 2.51 |
| 9 | array_pop | 33 | 2.37 |
| 10 | array_shift | 31 | 2.23 |
| 11 | explode | 30 | 2.16 |
| 12 | ini_set | 29 | 2.08 |
| 13 | header | 27 | 1.94 |
| 14 | urldecode | 23 | 1.65 |
| 15 | call_user_func_array | 22 | 1.58 |
| 16 | func_get_args | 21 | 1.51 |
| 17 | chr | 17 | 1.22 |
| 18 | array_keys | 16 | 1.15 |
| 19 | array_unshift | 15 | 1.08 |
| 20 | preg_match | 15 | 1.08 |
| 21 | preg_replace_callback | 15 | 1.08 |
| 22 | in_array | 15 | 1.08 |
| 23 | is_array | 14 | 1.01 |
| 24 | strtr | 14 | 1.01 |
| 25 | array_filter | 13 | 0.93 |
| 26 | strpos | 12 | 0.86 |
| 27 | md5 | 12 | 0.86 |
| 28 | parse_url | 12 | 0.86 |
| 29 | dirname | 11 | 0.79 |
| 30 | unserialize | 11 | 0.79 |
| 31 | max | 11 | 0.79 |
| 32 | gmdate | 10 | 0.72 |
| 33 | strlen | 9 | 0.65 |
| 34 | printf | 9 | 0.65 |
| 35 | time | 9 | 0.65 |
| 36 | pg_query | 9 | 0.65 |
| 37 | serialize | 8 | 0.57 |
| 38 | round | 8 | 0.57 |
| 39 | array_walk | 8 | 0.57 |
| 40 | array_flip | 8 | 0.57 |
| 41 | date | 8 | 0.57 |
| 42 | array_unique | 8 | 0.57 |
| 43 | ksort | 8 | 0.57 |
| 44 | str_repeat | 7 | 0.50 |
| 45 | mysqli_query | 7 | 0.50 |
| 46 | array_map | 7 | 0.50 |
| 47 | asort | 7 | 0.50 |
| 48 | mysql_query | 7 | 0.50 |
| 49 | file_get_contents | 6 | 0.43 |
| 50 | function_exists | 6 | 0.43 |
| 51 | register_shutdown_function | 6 | 0.43 |
| 52 | array_reverse | 6 | 0.43 |
| 53 | ceil | 5 | 0.36 |
| 54 | fclose | 5 | 0.36 |
| 55 | urlencode | 5 | 0.36 |
| 56 | xml_parser_create | 5 | 0.36 |
| 57 | uasort | 5 | 0.36 |
| 58 | file | 5 | 0.36 |
| 59 | strstr | 5 | 0.36 |
| 60 | basename | 5 | 0.36 |
| 61 | base64_encode | 5 | 0.36 |
| 62 | bcmod | 5 | 0.36 |
| 63 | min | 5 | 0.36 |
| 64 | strtolower | 5 | 0.36 |
| 65 | floor | 4 | 0.29 |
| 66 | array_merge_recursive | 4 | 0.29 |
| 67 | array_slice | 4 | 0.29 |
| 68 | preg_match_all | 4 | 0.29 |
| 69 | ob_start | 4 | 0.29 |
| 70 | mysql_connect | 4 | 0.29 |
| 71 | abs | 4 | 0.29 |
| 72 | realpath | 4 | 0.29 |
| 73 | ltrim | 4 | 0.29 |
| 74 | mail | 4 | 0.29 |
| 75 | preg_split | 4 | 0.29 |
| 76 | base64_decode | 4 | 0.29 |
| 77 | chmod | 4 | 0.29 |
| 78 | array_key_exists | 4 | 0.29 |
| 79 | call_user_func | 4 | 0.29 |
| 80 | ob_end_clean | 4 | 0.29 |
| 81 | ord | 4 | 0.29 |
| 82 | array_values | 3 | 0.22 |
| 83 | is_numeric | 3 | 0.22 |
| 84 | xml_parser_free | 3 | 0.22 |
| 85 | debug_backtrace | 3 | 0.22 |
| 86 | pg_last_error | 3 | 0.22 |
| 87 | is_dir | 3 | 0.22 |
| 88 | intval | 3 | 0.22 |
| 89 | xml_set_character_data_handler | 3 | 0.22 |
| 90 | is_string | 3 | 0.22 |
| 91 | stripslashes | 3 | 0.22 |
| 92 | sort | 3 | 0.22 |
| 93 | fopen | 3 | 0.22 |
| 94 | ini_get | 3 | 0.22 |
| 95 | xml_set_element_handler | 3 | 0.22 |
| 96 | trigger_error | 3 | 0.22 |
| 97 | extract | 3 | 0.22 |
| 98 | is_object | 3 | 0.22 |
| 99 | array_diff | 3 | 0.22 |
| 100 | link | 3 | 0.22 |
Total Drupal Functions Used: 1647
Total Custom Drupal Function calls in Drupal source code: 6819.
| Rank | Function | Occurrences | Per Cent |
|---|
| 1 | t | 1133 | 16.62 |
| 2 | theme | 273 | 4.00 |
| 3 | db_query | 230 | 3.37 |
| 4 | drupal_set_message | 214 | 3.14 |
| 5 | variable_get | 148 | 2.17 |
| 6 | drupal_render | 113 | 1.66 |
| 7 | form_set_error | 89 | 1.31 |
| 8 | check_plain | 80 | 1.17 |
| 9 | watchdog | 78 | 1.14 |
| 10 | l | 73 | 1.07 |
| 11 | st | 68 | 1.00 |
| 12 | drupal_set_title | 66 | 0.97 |
| 13 | drupal_get_form | 59 | 0.87 |
| 14 | variable_set | 52 | 0.76 |
| 15 | system_settings_form | 43 | 0.63 |
| 16 | cache_clear_all | 43 | 0.63 |
| 17 | update_sql | 40 | 0.59 |
| 18 | drupal_goto | 39 | 0.57 |
| 19 | drupal_add_js | 38 | 0.56 |
| 20 | db_result | 34 | 0.50 |
| 21 | url | 34 | 0.50 |
| 22 | theme_get_setting | 33 | 0.48 |
| 23 | confirm_form | 32 | 0.47 |
| 24 | base_path | 27 | 0.40 |
| 25 | pager_query | 27 | 0.40 |
| 26 | drupal_add_css | 27 | 0.40 |
| 27 | module_invoke | 27 | 0.40 |
| 28 | format_date | 26 | 0.38 |
| 29 | check_url | 26 | 0.38 |
| 30 | drupal_not_found | 25 | 0.37 |
| 31 | db_fetch_object | 25 | 0.37 |
| 32 | module_invoke_all | 22 | 0.32 |
| 33 | drupal_attributes | 19 | 0.28 |
| 34 | drupal_alter | 19 | 0.28 |
| 35 | drupal_map_assoc | 19 | 0.28 |
| 36 | db_query_range | 18 | 0.26 |
| 37 | language_list | 17 | 0.25 |
| 38 | get_t | 17 | 0.25 |
| 39 | drupal_add_tabledrag | 17 | 0.25 |
| 40 | xmlrpc_error | 17 | 0.25 |
| 41 | language_default | 16 | 0.23 |
| 42 | arg | 16 | 0.23 |
| 43 | template_preprocess | 16 | 0.23 |
| 44 | _locale_import_message | 15 | 0.22 |
| 45 | format_plural | 15 | 0.22 |
| 46 | stdClass | 15 | 0.22 |
| 47 | _user_mail_text | 14 | 0.21 |
| 48 | drupal_bootstrap | 14 | 0.21 |
| 49 | menu_get_item | 14 | 0.21 |
| 50 | drupal_set_header | 13 | 0.19 |
| 51 | menu_rebuild | 13 | 0.19 |
| 52 | cache_set | 12 | 0.18 |
| 53 | db_add_field | 12 | 0.18 |
| 54 | _db_query | 12 | 0.18 |
| 55 | form_error | 12 | 0.18 |
| 56 | variable_del | 12 | 0.18 |
| 57 | db_fetch_array | 12 | 0.18 |
| 58 | module_list | 12 | 0.18 |
| 59 | drupal_mail | 11 | 0.16 |
| 60 | drupal_get_destination | 11 | 0.16 |
| 61 | drupal_load | 11 | 0.16 |
| 62 | batch_process | 11 | 0.16 |
| 63 | batch_get | 11 | 0.16 |
| 64 | drupal_access_denied | 11 | 0.16 |
| 65 | hook_schema | 10 | 0.15 |
| 66 | form_set_value | 10 | 0.15 |
| 67 | _db_query_callback | 10 | 0.15 |
| 68 | node_load | 9 | 0.13 |
| 69 | node_get_types | 9 | 0.13 |
| 70 | module_rebuild_cache | 9 | 0.13 |
| 71 | menu_link_save | 9 | 0.13 |
| 72 | file_directory_path | 9 | 0.13 |
| 73 | form_clean_id | 9 | 0.13 |
| 74 | conf_path | 9 | 0.13 |
| 75 | image_get_info | 9 | 0.13 |
| 76 | update_get_projects | 9 | 0.13 |
| 77 | db_change_field | 9 | 0.13 |
| 78 | drupal_json | 8 | 0.12 |
| 79 | file_scan_directory | 8 | 0.12 |
| 80 | batch_set | 8 | 0.12 |
| 81 | _form_set_class | 8 | 0.12 |
| 82 | cache_get | 8 | 0.12 |
| 83 | module_load_include | 8 | 0.12 |
| 84 | tablesort_sql | 8 | 0.12 |
| 85 | install_task_list | 8 | 0.12 |
| 86 | _db_create_key_sql | 8 | 0.12 |
| 87 | _db_error_page | 8 | 0.12 |
| 88 | drupal_get_normal_path | 8 | 0.12 |
| 89 | b | 8 | 0.12 |
| 90 | hook_forms | 7 | 0.10 |
| 91 | drupal_maintenance_theme | 7 | 0.10 |
| 92 | drupal_set_content | 7 | 0.10 |
| 93 | module_load_install | 7 | 0.10 |
| 94 | file_create_path | 7 | 0.10 |
| 95 | drupal_query_string_encode | 7 | 0.10 |
| 96 | menu_link_delete | 7 | 0.10 |
| 97 | _db_create_field_sql | 7 | 0.10 |
| 98 | menu_execute_active_handler | 7 | 0.10 |
| 99 | module_exists | 7 | 0.10 |
| 100 | _locale_get_predefined_list | 7 | 0.10 |
Date Published: Oct 24, 2009 - 12:05 am
Robert Scoble interviewed Dan Olsen, the founder of Yourversion in this
Building 43 interview. I make a cameo appearance as a PHP hacker.
Date Published: Oct 07, 2009 - 9:42 pm
Here are a couple of PDFs that you might find informative. I submitted the recursion essay to Headfirst Books as a sample of my writing within their format. The REST essay was prepared for my PHP course. You'll have to provide the soundtrack yourself. Imagine that my delivery is a lot like Brad Pitt's in
Fight Club...if you want.
Date Published: Jul 22, 2009 - 10:09 pm
At this year's O'Reilly Open Source Conventions, Chris Shifflet and Sean Coates, will present "PHP: The Good Parts." This blog is not connected in any with with O'Reilly or OSCON. However, we wish them well, and welcome any spillover that wanders to this site.
As for our name (
PHP: The Good Parts), it is obvioulsy inspired by Douglas Crockford's great book about Javascript's good parts. If you're interested in making sense of Javascript's mysterious inner workings,
Javascript: The Good Parts is the go-to book.


Date Published: Jul 13, 2009 - 1:16 pm
In PHP parlance a
variable variable is a variable that holds a the name of another variable of any data type. In other words, a
variable variable is an example of
dynamic typing, or
duck typing. Dynamic typing and duck typing are two features that get a lot of attention in object oriented languages like Ruby and Python because they're useful for doing
magic tricks. Rather than muddy the water be talking of this mysterious thing called
magic, I'll call it what it is: dynamic typing.
Although dynamic typing is one of PHP's most useful features, beginning PHP programmers can find it confusing. The terminology itself---
variable variables---is a little too clever to be useful. Moreover, when variable variables are discussed, they are usually shown in non-productive examples, like this:
1 $place = 'The Big Apple'; // $place can be written ${place}
2 $holder = 'place'; // Holds the name of the $place variable
3 echo $$holder; // ==> The Big Apple
How it worksIn line 1 we assign the value "
The Big Apple" to
$place.
In line 2 we assign
$holder the value '
place.'
But what's going on with the '
$$' in line 3? This bit of syntax is where PHP processes the variable variable.
Let's consider how PHP handles line 3.
3 echo $$holder;
First, we need to remind ourselves that PHP parses each line from
right to
left. When PHP encounters the '
$$', it processes the rightmost '$' first. We can illustrate this by rewriting our code to wrap the first occurence in braces:
${$holder} ~ ${${holder}} ~ $$holder // these three forms are equivalentWe can take this one step further and do variable substitution on
$holder. In expressions, PHP replaces '
$' variables with the values they refer to. In this case, '
$holder' will be dereferenced and the value "
place" will replace it. Now our code looks like this:
${'place'}We still have the leftmost '
$' and the '
place' within the braces, which becomes:
$place
A synopsis of the process would look like this:
6 5 4 3 2 1
'The Big Apple' ~ $place ~ ${'place'} ~ ${$holder} ~ ${${holder}} ~ $$holder
Although this example shows the process of using variable variables, it doesn't give us a reason to use them in our programs. To see how to make use of variable variables, we need to see a few more examples.
What's in a Variable?In a dynamically typed language, it turns out that variables don't really hold anything in particular. PHP variables simply point to something stored at some area of memory in your program. That something might be a string, a number, a filehandle, or any other kind of object. Whatever happens to be at the target location is available through the variable. Because variables are able to refer to any kind of PHP data type, we can do some of those so-called
magical things quite conveniently.
Variables Used as FunctionsIn the following example, we will use variables to refer to the names of some functions.
Let's assume for a moment that we have to create an HTML table using a multi-dimensional array that contains arrays of names.These arrays could be created by a query to a database, or they could be created from any other source. Our script will not care where the arrays came from. Our job is to put the names in each array into an HTML row, with each element encased in
tags, and the tags for each row encased in | tags, all within containing tags.
The array looks like this:
/** An array of names in an orderly format, as from a database. */
$names = array(
array('al', 'bob','cary','dave','ed'),
array('fred', 'george','harriet','isadore','jake'),
array('karen', 'louise','marion','ned','olive'),
array('paul', 'quincy','rhoda','sarah','terry'),
array('unknown', 'vera','whitey','xavier','zed')
);
?>
There are lots of ways to solve this problem, but for this example we'll use variable variables to process a list of functions.
/**
* Create some HTML function
*/
/** Creates elements. */ function td($array) { $out = array(); foreach($array as $k => $a) { $out[] = " | " . implode(" | \n ", $a) . " | \n";
}
return $out;
}
/** Creates elements using elements. */ function tr($tds) { $out = ''; foreach($tds as $row) { $out .= " |
\n" . $row . '
'."\n";
}
return $out;
}
/** Creates a table using elements. */
function table($trs){
return '' . "\n";
}
/**
* The function names are entered in the array
* in the order that they will be executed.
*/
$funcs = array('td','tr','table');
/** Feed the $input array to the functions. */
$input = $names;
foreach($funcs as $function) {
$input = $function($input);
}
?>
Names
The output:
Names
al |
bob |
cary |
dave |
ed |
fred |
george |
harriet |
isadore |
jake |
karen |
louise |
marion |
ned |
olive |
paul |
quincy |
rhoda |
sarah |
terry |
unknown |
vera |
whitey |
xavier |
zed |
Run this code yourself to see the little table that pops out of this code. You can see that each function in the array is run as when $func refers to it. The value passed into the function is the value returned by the previous function. By the way, print() and echo() are not functions, so this technique will not work with them.
Next
In the next PHP Good Part we'll extend variable variables a little further to create pretty URLs.
Until then, keep hacking...
--Douglas Putnam
Date Published: Dec 11, 2008 - 2:35 pm
Have you ever said, "Someone should (fill in the blank)...?" I've been saying that to myself since I read "Javascript: The Good Parts." Someone should write a book about PHP's good parts. And it should be me. So, yesterday I decided to kick out the jams and get started on a project that's been on my mind recently:
PHP -> The Good Parts.
The plan is a short guide to PHP—not a "nutshell book"—but subset of PHP comprised of the awesome parts, and the coding practices that use these functions. This will not be another 4 pound compilation of PHP documentation. Nope, this will be short and sweet, and useful—something I would want to read myself.
Here's some of the things you never see in run-of-the-mill PHP books.
- How to build a reusable Rails-style framework in 2o minutes.
- Awesome form validation techniques, with error display and custom messages.
- A 40 line object-oriented MVC framework that handles 99% of your "framework" needs.
- Fabulous array tricks for printing multi-column sorted tables.
- Implementing an Rails-style Active Record Class in less than 100 lines. This really rocks and is 100% useful.
- "Magic" tricks that we use on the workroom floor, but never put into books.
Stay tuned. It's going to be a great ride.
--Douglas Putnam
Date Published: Nov 24, 2008 - 9:43 pm
Everyone in the business knows that PHP is the Brawny Brick Layer of web development, but did you know that not
all of PHP is really that great? In fact, some of the most used features of PHP are really a big waste of your time and money. PHP can send your web project to Heaven, and the other parts, the Bad parts, will send you spiraling down into the Pit of Despair.
The purpose of PHP—The Good Parts is to point out the Good, and help you to avoid the Bad and Ugly, and go straight to the Blissful.
We believe that you need 3% of PHP's 5607 built-in functions to do 97% of the PHP projects you'll face. We'll boldly show you the names of the functions, how to use them, and, best of all, how to write idiomatic PHP that saves time and makes money. Along the way, we'll be candid and opinionated and we'll lay it all on the table.
I've read dozens of PHP books over the last 10 years. I've taught hundreds of students the keys to successful PHP development. Now I'm putting it into a small, intense package: PHP—The Good Parts.
Douglas Putnam
HackingTheValley.blogspot.com
Date Published: Nov 24, 2008 - 9:00 pm
u-mp9941 serv 0.9874 seconds to generate.