Sunday, 30 September 2012

spl_autoload_register

bool spl_autoload_register ([ callable $autoload_function [, bool $throw = true [, bool $prepend = false ]]] )
Register given function as __autoload() implementation
Register a function with the spl provided __autoload stack. If the stack is not yet activated it will be activated.

<?php// function __autoload($class) {
//     include 'classes/' . $class . '.class.php';
// }
function my_autoloader($class) {
    include 
'classes/' $class '.class.php';
}
spl_autoload_register('my_autoloader');// Or, using an anonymous function as of PHP 5.3.0spl_autoload_register(function ($class) {
    include 
'classes/' $class '.class.php';
});
?>

5.3.0 Namespaces support was introduced. 5.3.0 The prepend parameter was added.

PHP Strategy Pattern OOP | 29

json_encode - Returns the JSON representation of a value

string json_encode ( mixed $value [, int $options = 0 ] )
Returns the JSON representation of a value
Returns a string containing the JSON representation of value.

<?php
$arr 
= array('a' => 1'b' => 2'c' => 3'd' => 4'e' => 5);

echo 
json_encode($arr);?>

5.4.0 JSON_PRETTY_PRINT, JSON_UNESCAPED_SLASHES, and JSON_UNESCAPED_UNICODE options were added. 5.3.3 JSON_NUMERIC_CHECK option was added. 5.3.0 The options parameter was added.

JSON - PHP y Javascript