Skip to content

Instantly share code, notes, and snippets.

@k-holy
Created October 27, 2011 02:36
Show Gist options
  • Save k-holy/1318652 to your computer and use it in GitHub Desktop.
Save k-holy/1318652 to your computer and use it in GitHub Desktop.
PEAR形式のみ対応のautoload実装(PHP5.3.2以降)
<?php
set_include_path('/path/to/pear' . PATH_SEPARATOR . get_include_path());
spl_autoload_register(function($className) {
if (false !== ($path = stream_resolve_include_path(
str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'))
) {
return include $path;
}
return false;
}, true, true);
print new PEAR_Exception('GRRRR');
@k-holy
Copy link
Author

k-holy commented Oct 27, 2011

ありがとうございます。
PHPUnitが3.6以降オートローダ前提のコードに変わったようで、Symfony2のチュートリアルでエラー発生ということがありまして、ここにメモしました。

@koriym
Copy link

koriym commented Oct 27, 2011

stream_resolve_include_path
これは知りませんでした。以前から欲しかった関数です。

@k-holy
Copy link
Author

k-holy commented Oct 27, 2011

はい、この関数のおかげでエラー制御演算子やerror_reporting()を使わなくても良くなりました。
PHPマニュアルのinclude()やinclude_pathディレクティブのページからリンクされていないので、私も長らく気付きませんでした…。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment