Using OOP styles for Drupal 7: callbacks

Drupal 7 was created mainly with a procedural style but OOP styles can be used in many parts of it.

For example, there're many callbacks used in the Drupal 7 system. Originally they're expected being functions but some callbacks can be replaced to methods. Here are some examples.

Batch callbacks.

We can use methods for batch callbacks. Because the callback is stored in the database with a serialized manner and invoked with call_user_func_array().

When to use call_user_func() and 'funcname'() in PHP?

There are 2 ways to call a function whose name is set at runtime in PHP. One is call_user_func() and another is 'funcname'().

<?php

$funcname = 'array_sum';

// call_user_func()
call_user_func($funcname, [1, 2, 3]);  // => 6

// 'funcname'()
$funcname([1, 2, 3]);  // => 6

At a glance these 2 methods are completely same but there are some important differences between them. Let's check them one by one.

A Bash function to check Drupal database sizes

At times I'd like to check the size of databases used by Drupal.

But I don't like to launch apps like phpMyAdmin and Sequel Pro only for that. So I wrote a tiny Bash function to check Drupal database sizes.

ページ