LoginSignup
2
0

More than 3 years have passed since last update.

PHP Version 5.4.31 から PHP Version 7.4.10 への移行でつまずいた事まとめ

Last updated at Posted at 2020-10-17

PHP Version 5.4.31 から PHP Version 7.4.10 への移行にあたって、つまずいた事をまとめてみました。

この記事では Windows 10 Pro にインストールした、pleiades-2020-09-ultimate-win-64bit-jre_20200920.zip を使っています。

PEAR::Auth

PEAR::Auth のインストール

pear install -a Auth MDB2 MDB2#MysqliAuth

でつまずきました。

xamppのPHP、pearのupgradeをしてみる、DBを入れてみる件
を参照して、解決しました。

.htaccess の修正

 .htaccess(修正前)
<IfModule mod_php5.c>
  php_value auto_prepend_file "include/MyAuth.php"
</IfModule>
・・・後略・・・

と書いているのに MyAuth.php の処理を通りませんでした。

http://localhost/dashboard/phpinfo.php
の「Loaded Modules 」で確認してみたら、
mod_php5 でなく mod_php7 にバージョンアップしていました。
なので、<IfModule mod_php7.c> を追記しました。

 .htaccess(修正後)
<IfModule mod_php5.c>
  php_value auto_prepend_file "include/MyAuth.php"
</IfModule>

<IfModule mod_php7.c>
  php_value auto_prepend_file "include/MyAuth.php"
</IfModule>
・・・後略・・・

pear/Auth.php のソースを修正

new の前の & を削除

XX\xampp\apache\logs\error.log
・・・前略・・・
[Tue Oct 13 20:47:32.722548 2020] [php7:notice] [pid 36512:tid 1916] [client ::1:56879] PHP Parse error:  syntax error, unexpected 'new' (T_NEW) in XX\\xampp\\php\\pear\\Auth.php on line 469
・・・後略・・・

new の前の & を削りました。

XX\xampp\php\pear\Auth.php(修正前)
    function &_factory($driver, $options = '')
    {
        $storage_class = 'Auth_Container_' . $driver;
        include_once 'Auth/Container/' . $driver . '.php';
        $obj =& new $storage_class($options);
・・・後略・・・
XX\xampp\php\pear\Auth.php(修正後)
    function &_factory($driver, $options = '')
    {
        $storage_class = 'Auth_Container_' . $driver;
        include_once 'Auth/Container/' . $driver . '.php';
//        $obj =& new $storage_class($options);
        $obj = new $storage_class($options);
・・・後略・・・

pear/MDB2.php のソースを修正 ※結局 MDB2 を使うのを断念

new の前の & を削除

PHPの実行結果のエラー表示.
Parse error: syntax error, unexpected 'new' (T_NEW) in XX\xampp\php\pear\MDB2.php on line 390

new の前の & を削りました。

XX\xampp\php\pear\MDB2.php(修正前)
・・・前略・・・
        $db =& new $class_name();
        $db->setDSN($dsninfo);
        $err = MDB2::setOptions($db, $options);
        if (PEAR::isError($err)) {
            return $err;
        }
・・・他にも& new多数あり・・・
XX\xampp\php\pear\MDB2.php(修正前)
・・・前略・・・
//        $db =& new $class_name();
        $db = new $class_name();
        $db->setDSN($dsninfo);
        $err = MDB2::setOptions($db, $options);
        if (PEAR::isError($err)) {
            return $err;
        }
・・・他にも& new多数あり・・・

count の仕様変更に対応

PHP7.3バージョンアップでcount関数エラー
を参照して、
旧countと同じ動作をする、get_countを追加して、
countをget_countに置換しました。

PHPの実行結果のエラー表示.その2
Parse error: syntax error, unexpected 'new' (T_NEW) in XX\xampp\php\pear\MDB2.php on line 1889
XX\xampp\php\pear\MDB2.php(修正前)
・・・前略・・・
    function parseDSN($dsn)
    {
・・・中略・・・
        if (!count($dsn)) {
            return $parsed;
        }
・・・他多数・・・
XX\xampp\php\pear\MDB2.php(修正後)
・・・前略・・・
// 旧countと同じ動作をする、get_countを追加
if (!function_exists('get_count')) {
    function get_count($var) {
        return ((is_array($var) || $var instanceof Countable)?count($var):0);
    }
}
・・・中略・・・
    function parseDSN($dsn)
    {
・・・中略・・・
//        if (!count($dsn)) {
        if (!get_count($dsn)) {
            return $parsed;
        }
・・・他多数・・・

\xampp\php\pear\MDB2\Driver\mysqli.php

new の前の & を削除

Parse error: syntax error, unexpected 'new' (T_NEW) in xx\xampp\php\pear\MDB2\Driver\mysqli.php on line 940
xx\xampp\php\pear\MDB2\Driver\mysqli.php(修正前)
・・・前略・・・
        $obj =& new $class_name($this, $statement, $positions, $query, $types, $result_types, $is_manip, $limit, $offset);
・・・中略・・・
                $row = &new $object_class($row);
・・・後略・・・
xx\xampp\php\pear\MDB2\Driver\mysqli.php(修正後)
//        $obj =& new $class_name($this, $statement, $positions, $query, $types, $result_types, $is_manip, $limit, $offset);
        $obj = new $class_name($this, $statement, $positions, $query, $types, $result_types, 
・・・中略・・・
//                $row = &new $object_class($row);
                $row = new $object_class($row);
・・・後略・・・

pear/MDB2.php を使うのを断念

ここまで修正してきても、下記のエラーが出るので、pear/MDB2.php を使うのを断念

Fatal error: Call to undefined function: MDB2_Driver_mysqli::raiseError(). in C:\pleiades-2020-09\xampp\php\pear\MDB2.php on line 1960

Call Stack
#   Time    Memory  Function    Location
1   0.0175  419536  {main}( )   ...\MyAuth.php:0
2   25.7579 542648  Auth->start( )  ...\MyAuth.php:70
3   25.7581 542648  Auth->login( )  ...\Auth.php:535
4   25.7641 1215208 Auth_Container_MDB2->fetchData( ???, ???, ??? ) ...\Auth.php:563
5   25.7641 1215208 Auth_Container_MDB2->_prepare( )    ...\MDB2.php:298
6   25.7641 1215208 Auth_Container_MDB2->_connect( ??? )    ...\MDB2.php:170
7   25.7641 1215208 MDB2::connect( ???, ??? )   ...\MDB2.php:114
8   25.7657 1441576 MDB2_Driver_mysqli->connect( )  ...\MDB2.php:458
9   25.7771 1441736 MDB2_Driver_mysqli->raiseError( ???, ???, ???, ???, ??? )   ...\mysqli.php:437
10  25.7772 1443424 MDB2_Driver_mysqli->raiseError( ???, ???, ???, ???, ???, ???, ??? ) ...\MDB2.php:1462
11  25.7772 1443800 MDB2_Driver_mysqli->__call( ???, ??? )  ...\MDB2.php:1462
12  25.7772 1444632 trigger_error ( ???, ??? )  ...\MDB2.php:1960

PEAR::Auth で PDO を使う

PEAR::AuthにPDOのContainerを追加してみる(検証中)
と、
php7・PDOでも認証ライブラリでSentinelではなくPEAR::Authを使った
を参照し、
xx\xampp\php\pear\Auth\Container
に、PDO.php を追加

PDO を使うために、認証処理用の自前プログラム MyAuth.php を下記の通り修正しました。

MyAuth.php(修正前)
<?php
require_once 'Auth/Auth.php';
・・・中略・・・
$params = array (
        'dsn' => 'mysqli://' . DB_USERNAME . ':' . DB_PASSWD . '@' . DB_HOST . '/' . DB_DBNAME,
        'table' => AUTH_TABLE,
        'usernamecol' => AUTH_USERNAME_COL,
        'passwordcol' => AUTH_PASSWORD_COL
);
$auth = new Auth ( 'MDB2', $params, 'myLogin' );
・・・後略・・・
MyAuth.php(修正後)
<?php
require_once 'Auth/Auth.php';
・・・中略・・・
$options = array (
    // コネクションプーリング
    // 1つのコネクションを使いまわすのがボトルネックとなりスケールしないため、
    // スレッドキャッシュ(max_connections、thread_cache_size指定)との合わせ技で、
    // コネクションプーリングの設定を、コメントアウトする。
    // PDO::ATTR_PERSISTENT => true,
    // エラー時に例外を投げる
    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
);
$params = array (
    'table' => AUTH_TABLE,
    'usernamecol' => AUTH_USERNAME_COL,
    'passwordcol' => AUTH_PASSWORD_COL,
    'dsn' => 'mysql:dbname=' . DB_DBNAME . '; host=' . DB_HOST . '; charset=utf8',
    'db_fields' => '',
    'cryptType'=> 'md5',
    'db_options'  => $options,
    'db_where' => '',
    'auto_quote' => false,
    'db_user' => DB_USERNAME,
    'db_password' => DB_PASSWD
);
$auth = new Auth ( 'PDO', $params, 'myLogin' );

count の仕様変更

PHP7.2のcountにハマった話

        // count の仕様変更に対応
        //if (0 < count ( $map )) {
    // NULLチェックに使えなくなった。
        if (0 < isset ( $map )) {

php_error_log に「PHP Warning: PHP Startup: Unable to load dynamic library 'pdo_sqlite'」

PHPの「Unable to load dynamic library」を解消する方法
https://qiita.com/joe_hirata/items/94c8d56cdd0774779b39

Apacheのerror.logに AH01909

XAMPPのApacheでエラーが出た際の対処法
https://oxynotes.com/?p=8098

\xampp\apache\logs\error.log
[Sat Oct 31 20:18:16.089659 2020] [ssl:warn] [pid 9336:tid 576] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
\xampp\apache\conf\extra\httpd-ssl.conf
##
## SSL Virtual Host Context
##

<VirtualHost _default_:443>

#   General setup for the virtual host
DocumentRoot "C:/pleiades-2020-09/xampp/htdocs"
#ServerName www.example.com:443
ServerName localhost:443
ServerAdmin admin@example.com
ErrorLog "C:/pleiades-2020-09/xampp/apache/logs/error.log"
TransferLog "C:/pleiades-2020-09/xampp/apache/logs/access.log"
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0