PHP
All PHP functions have the global scope
4번독수리
2015. 12. 3. 16:14
http://php.net/manual/en/functions.user-defined.php
http://stackoverflow.com/a/14753616
The following codes use this feature for setting hex2bin() compartible in a class MyClass on PHP5.
class MyClass
{
public function __construct()
{
self::compat();
}
private static function compat()
{
if (!function_exists('hex2bin')) {
function hex2bin($hexString)
{
return pack('H*', $hexString);
}
}
}
public function foo($string)
{
return 'Hello '.hex2bin($string);
}
}
$MyObj = new MyClass();
echo $MyObj->foo('776f726c64');