Friday, 28 November 2014

spl_autoload What is spl_autoload function in php

spl_autoload What is spl_autoload function in php

void spl_autoload ( string $class_name [, string $file_extensions = spl_autoload_extensions() ] )
Default implementation for __autoload()
This function is intended to be used as a default implementation for __autoload(). If nothing else is specified and spl_autoload_register() is called without any parameters then this function will be used for any later call to __autoload().
spl_autoload_register() allows you to register multiple functions (or static methods from your own Autoload class) that PHP will put into a stack/queue and call sequentially when a "new Class" is declared.

Following is the example
 
<?php
spl_autoload_register('myAutoloader');
function loadAutoload($className){
    $path = '/path/to/class';
    include $path.$className.'.php';
}
$obj = new Zend_Log();
?>

Thursday, 27 November 2014

parse_ini_string - Parse a configuration string

array parse_ini_string ( string $ini [, bool $process_sections = false [, int $scanner_mode = INI_SCANNER_NORMAL ]] )
Parse a configuration string
parse_ini_string returns the settings in string ini in an associative array.

Function parse_ini_file doesn't parse a remote ini file if allow_url_include is off. But if allow_url_fopen is on, you can use parse_ini_string to parse a remote ini file after read its contents.
/**
* Assume that; allow_url_include=0 and allow_url_fopen=1
* (default values in php.ini)
*/

$iniUrl = 'http://website.com/remote/config.ini';
/**
* Warning: parse_ini_file(): http:// wrapper is disabled in the server configuration by allow_url_include=0
*/
$config = parse_ini_file($iniUrl);

/**
* works fine
*/
$config = parse_ini_string(file_get_contents($iniUrl));