Postingan lainnya
Bantu gan, cara alternatif menggunakan namespace di php 5.2
gan tolong bantu ane, namespace di 5.2 tidak jalan. ane baca2 namespace baru support di 5.3++ . yang ane tanyakan, gimana cara alternatif penggantian fungsi namespace di 5.2
file ShapeFileAutoloader.php
namespace ShapeFile;
class ShapeFileAutoloader
{
public static function register()
{
spl_autoload_register('static::loadClass');
}
public static function loadClass($class)
{
$prefix = __NAMESPACE__ . '\\';
$base_dir = __DIR__ . '/';
$prefix_len = strlen($prefix);
if (strncmp($prefix, $class, $prefix_len) !== 0) {
return;
}
$file = $base_dir . str_replace('\\', '/', substr($class, $prefix_len)) . '.php';
if (file_exists($file)) {
require($file);
}
}
}
ini untuk panggil fungsi diatas
\ShapeFile\ShapeFileAutoloader::register();
// Import classes
use \ShapeFile\ShapeFile;
use \ShapeFile\ShapeFileException;
0
Tanggapan
Namespaces are not supported prior to 5.3. There isn't really a way to adapt for them into 5.2 unfortunately.
Belum ada Jawaban. Jadi yang pertama Jawaban
Login untuk ikut Jawaban