前提・実現したいこと
CentOS 5.5、PHP 5.2の環境にて、PearパッケージのAuth機能を使用していますが、環境が古いためPearパッケージの使用は継続しOSとPHPをバージョンアップして動作検証を行っています。
しかし、バージョンアップした環境だとAuth.phpで以下エラーが発生し動作しません。基本的なことで恐縮ですが、エラー原因がわからず、解決方法をご存じでしょうか。
発生している問題・エラーメッセージ
Fatal error: Uncaught Error: Class "Auth_Container_" not found in /usr/share/pear/Auth.php on line 470 Error: Class "Auth_Container_" not found in /usr/share/pear/Auth.php on line 470
該当のソースコード
php
1 function &_factory($driver, $options = '') 2 { 3 $storage_class = 'Auth_Container_' . $driver; 4 include_once 'Auth/Container/' . $driver . '.php'; 5// $obj =& new $storage_class($options); 6 $obj = new $storage_class($options); 7 return $obj; 8 }
補足情報(FW/ツールのバージョンなど)
エラーが発生した環境
CentOS 7.9
PHP 8.0
Apache 2.4.6
MySQL 8.0.27
PEAR 1.10.13
インストール済のPearパッケージ
Installed packages, channel pear.php.net: ========================================= Package Version State Archive_Tar 1.4.14 stable Auth 1.6.4 stable Auth_SASL 1.1.0 stable Console_Getopt 1.4.3 stable DB 1.11.0 stable Date 1.4.7 stable MDB2 2.4.1 stable Mail 1.4.1 stable Mail_Mime 1.10.11 stable Net_SMTP 1.10.0 stable Net_Sieve 1.4.5 stable Net_Socket 1.2.2 stable Net_URL 1.0.15 stable PEAR 1.10.13 stable PEAR_Manpages 1.10.0 stable Structures_Graph 1.1.1 stable XML_Util 1.4.5 stable
前提としてデザインメインのコピペプログラマーとしてお読みください。
PHP8の環境で動作確認取れたので共有させていただきます。
3行目:$storage_class = 'Auth_Container_' . $driver;
の「$driver」の値、遡ると「function Auth($storageDriver ~省略」の「$storageDriver」が正常に受け渡しできていないため起こるエラーです。
私のコードでは
$myContainer = new Auth_Container($params);
$myAuth = new Auth($myContainer,'PDO','loginFunction');
として値の受け渡しを行っていたのですがPHP8ではクラス名とその内部の関数名が同一だと正常に動作しないようでしたので、下記のように関数名を「AuthFunc」に変更しました。
■変更前
class Auth {
function Auth($storageDriver, $options = '', $loginFunction = '', $showLogin = true)
{
}
}
■変更後
class Auth {
function AuthFunc($storageDriver, $options = '', $loginFunction = '', $showLogin = true)
{
}
}
そして前述のコードも・・・
■変更前
$myAuth = new Auth($myContainer,'PDO','loginFunction');
■変更後
$myAuth = new Auth();
$myAuth->AuthFunc($myContainer,'PDO','loginFunction');
としました。
あとPHP8で削除された「get_magic_quotes_gpc」でエラーになりますが、
該当部分見ていただければ分かると思います。
またPHP5.2の環境からだとPEARのDBも動作しないため、下記参考にPDOを導入することで動作するようになります。
参考)PEAR::AuthにPDOのContainerを追加してみる
https://seedslight.com/wp/archives/182
もう他の方法で解決済みだとは思いますが、検索でたどり着いたため後々の方のために共有させていただきました。乱文失礼いたします。