Skip to Main Content
PHP 5 Kochbuch, Third Edition
book

PHP 5 Kochbuch, Third Edition

by David Sklar, Adam Trachtenberg, Carsten Lucke, Matthias Brusdeylins, Ulrich Speidel, Stephan Schmidt
September 2009
Intermediate to advanced content levelIntermediate to advanced
912 pages
48h 11m
German
O'Reilly Verlag
Content preview from PHP 5 Kochbuch, Third Edition

6.10 Variable Funktionen aufrufen

Problem

Sie möchten in Abhängigkeit vom Wert einer Variablen unterschiedliche Funktionen aufrufen.

Lösung

Verwenden Sie die Funktion call_user_func():

function get_file($filename) { return file_get_contents($filename); }

$function = 'get_file';
$filename = 'graphic.png';

call_user_func($function, $filename); // Ruft get_file('graphic.png') auf.

Wenn Ihre Funktionen unterschiedliche Anzahlen von Argumenten entgegennehmen, verwenden Sie die Funktion call_user_func_array():

function get_file($filename) { return file_get_contents($filename); } function put_file($filename, $data) { return file_put_contents($filename, $data); } if ($action == 'get') { $function = 'get_file'; $args = array('graphic.png'); } elseif ($action ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

PHP programmieren unter Windows

PHP programmieren unter Windows

Arno Hollosi
CSS Kochbuch, 3rd Edition

CSS Kochbuch, 3rd Edition

Joergen Lang, Christopher Schmitt

Publisher Resources

ISBN: 9783868993271Purchase book