LoginSignup
boarder
@boarder

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

xoops php7.4に変更したらFatal error: Call to undefined method

解決したいこと

初めて投稿させていただきます。

現在XOOPSにてサイトを構築していますが、PHP5.6からPHP7.3に変更しましたら
色々不具合が出てきました。

XAMPPにてローカルで新しいPHP7.4でテストしていますが、
phpデバグにて取得したエラーログは以下の通りでした。(PHP7.3でも同じ)

発生している問題・エラー

Fatal error: Uncaught Error: Call to undefined method whatsnew_show_block_handler::happy_linux_build_cache() in C:\xampp\htdocs\20200703\main\modules\whatsnew\class\whatsnew_show_block_handler.php:93 Stack trace: #0 C:\xampp\htdocs\20200703\main\modules\happy_linux\include\functions.php(93): whatsnew_show_block_handler->__construct('whatsnew') #1 C:\xampp\htdocs\20200703\main\modules\whatsnew\include\functions.php(18): happy_linux_get_handler('show_block', 'whatsnew', 'whatsnew') #2 C:\xampp\htdocs\20200703\main\modules\whatsnew\blocks\block.new.php(55): whatsnew_get_handler('show_block', 'whatsnew') #3 C:\xampp\htdocs\20200703\main\modules\whatsnew\blocks\block.new.php(39): b_whatsnew_show_common('date', Array) #4 C:\xampp\htdocs\20200703\main\kernel\block.php(191): b_whatsnew_show_date(Array) #5 C:\xampp\htdocs\20200703\main\modules\legacy\kernel\Legacy_BlockProcedure.class.php(245): XoopsBlock->buildBlock() #6 C:\xampp\htdocs\20200703\main\modules\legacy\kernel\Legacy_Controller.class.php(426): Legacy_BlockProcedureAda in C:\xampp\htdocs\20200703\main\modules\whatsnew\class\whatsnew_show_block_handler.php on line 93
Warning [PHP]: Declaration of & happy_linux_basic_handler::getInstance($dirname) should be compatible with & happy_linux_error::getInstance() in file C:\xampp\htdocs\20200703\main\modules\happy_linux\class\basic_handler.php line 84 (1)
Fatal [PHP]: Uncaught Error: Call to undefined method whatsnew_show_block_handler::happy_linux_build_cache() in C:\xampp\htdocs\20200703\main\modules\whatsnew\class\whatsnew_show_block_handler.php:93 Stack trace: #0 C:\xampp\htdocs\20200703\main\modules\happy_linux\include\functions.php(93): whatsnew_show_block_handler->__construct('whatsnew') #1 C:\xampp\htdocs\20200703\main\modules\whatsnew\include\functions.php(18): happy_linux_get_handler('show_block', 'whatsnew', 'whatsnew') #2 C:\xampp\htdocs\20200703\main\modules\whatsnew\blocks\block.new.php(55): whatsnew_get_handler('show_block', 'whatsnew') #3 C:\xampp\htdocs\20200703\main\modules\whatsnew\blocks\block.new.php(39): b_whatsnew_show_common('date', Array) #4 C:\xampp\htdocs\20200703\main\kernel\block.php(191): b_whatsnew_show_date(Array) #5 C:\xampp\htdocs\20200703\main\modules\legacy\kernel\Legacy_BlockProcedure.class.php(245): XoopsBlock->buildBlock() #6 C:\xampp\htdocs\20200703\main\modules\legacy\kernel\Legacy_Controller.class.php(426): Legacy_BlockProcedureAda in file C:\xampp\htdocs\20200703\main\modules\whatsnew\class\whatsnew_show_block_handler.php line 93 (1)

または、問題・エラーが起きている画像をここにドラッグアンドドロップ。

該当するソースコード

class whatsnew_show_block_handler extends happy_linux_build_cache
{
    var $_DIRNAME;
    var $_DIR_MODULE;
    var $_URL_MODULE;

    var $_build;
    var $_system;

    var $_xoops_uid = 0;
    var $_cache_id  = null;
    var $_cache_id_guest = null;

    var $_TIME_PROHIBIT = 180;  // 180 sec
    var $_ICON_MAX_COL = 5;
    var $_MODE_BUILD   = 0;

    var $_DEBUG_FORCE  = false;

//---------------------------------------------------------
// constructor
//---------------------------------------------------------
function __construct( $dirname )
{
    $this->happy_linux_build_cache();    93行目

自分で試したこと

現在の環境は以下になります。

Distribution : XOOPS X(ten) 20181220
XC Legacyバージョン : XOOPS Cube Legacy 2.2.3 Beta 1
デフォルト・サイトテーマ : x-mas
デフォルトのテンプレート・セット : template
使用言語 : ja_utf8
デバッグモードを有効にする : PHPデバグ
オペレーティングシステム : Windows
サーバー : Apache/2.4.46 (Win64) OpenSSL/1.1.1g PHP/7.4.10
ユーザーエージェント : Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36
PHPバージョン : 7.4.10
MySQLのバージョン : 10.4.14-MariaDB

色々ネットで調べてみて、親クラスのコンストラクターを呼び出す所でエラーみたいですが
以下のページを見つけて、3つの動作をしてみましたが、うまくいきません。
https://stackoverflow.com/questions/46890396/php-error-fatal-error-call-to-undefined-method-php-5-2-to-php-7

うまく修復できる方法やアドバイスを頂ければと思います。
どうかよろしくお願いいたします。

0

13Answer

happy_linux_build_cache()happy_linux_build_cacheクラスのメソッドでしょうか?
だとすればhappy_linux_build_cacheクラスの詳細も記載したほうが良いと思います。

推測になりますがhappy_linux_build_cache()がコンストラクタだと仮定して、__construct()にリネームして次のように呼び出すとどうでしょうか?

function __construct( $dirname )
{
    parent::__construct();
}
0

blue32aさん

早速やってみまして、うまく表示されました。

ありがとうございます。

何日もやっていましたが、初めてここで質問したら、こんなに早く解決しました。

まだ他の不具合もありそうなので、機会がありましたらまたよろしくお願いします。

0

blue32aさん

うまく行ったと思っていましたが、だめでした。

プログラミングは素人ですが、色々調べてみて
class whatsnew_show_block_handler extends happy_linux_build_cache となっているので

happy_linux_build_cache()は親クラスと理解してます。

happy_linux_build_cacheクラスの詳細も記載とのことですが、どのようなものを記載すればいいでしょうか?

ご教示よろしくお願いします。

0

happy_linux_build_cacheクラスの詳細も記載とのことですが、どのようなものを記載すればいいでしょうか?

基本的にはソースコード全てです。
ご自身である程度あたりをつけられるなら部分的な情報でも大丈夫です。
コードの量が多いと読む方も大変なので、その場合はGitHubなどのサービスで公開するのも良いと思います。

Call to undefined method whatsnew_show_block_handler::happy_linux_build_cache()

happy_linux_build_cache()が未定義、つまり存在しないということなので、
単純に考えるならwhatsnew_show_block_handlerクラスもしくはその親クラスにそれが存在しないということになります。
その点は確認されましたか?

コンストラクタについて言及したのは、クラス名と同名の関数をコンストラクタとするのは古い形式でありPHP7.0から非推奨となったからです。
コンストラクタとデストラクタ

0

blue32aさん

お返事ありがとうございます。

昨晩送ったのですが、Qiitaのほうでスパム判定が出て、メッセージが削除され、先程解除されてホッとしています。

エラーメッセージでは未定義みたいな感じですが、なにぶん素人でどうすればいいか
意味自体もよくわかりません。
69行目が以下になっているので、親クラスがhappy_linux_build_cacheでいいのでは?
class whatsnew_show_block_handler extends happy_linux_build_cache

whatsnew_show_block_handler.php on line 94となっているのでwhatsnew_show_block_handler.phpのソースコードの以下でよろしいでしょうか?
最初のコメント行も含め307行あります。

GitHubでの公開方法がよくわからなく、ここにコピペします。

よろしくお願いします。

// $Id: whatsnew_show_block_handler.php,v 1.2 2011/12/31 02:08:47 ohwada Exp $

// 2010-04-25 Marijuana 
// whatsnew_ping -> whatsnew_ping_handler

// 2008-10-11 nao-pon
// _get_template_filename()
// http://linux.ohwada.jp/modules/newbb/viewtopic.php?topic_id=866&forum=8

// 2007-12-01 K.OHWADA
// DEBUG_FORCE

// 2007-10-10 K.OHWADA
// rename whatsnew_show_block to whatsnew_show_block_handler
// divid to whatsnew_build_block_handler.php whatsnew_collect_plugins.php
// happy_linux_build_cache

// 2007-08-01 K.OHWADA
// BUG: cannot show HTML entity like ä ©

// 2007-05-12 K.OHWADA
// module dupulication
// XC 2.1 system comment
// divid to whatsnew_config_basic_handler whatsnew_module_basic_handler
// WHATSNEW_FIELD_PLUGIN -> 'plugin'

// 2006-07-17 K.OHWADA
// BUG 3142: include plugin more than one time

// 2006-06-25 K.OHWADA
// add get_plugins()

// 2006-06-20 K.OHWADA
// assign variable into template: date_m, date_l
// add _get_config()

// 2006-01-27 K.OHWADA
// BUG 3508: Undefined index: description
// REQ 3509: put into spacing in a summary 
//   add fucntion _add_space()

// 2006-01-10 K.OHWADA
// BUG: Undefined offset

// 2005-11-16 K.OHWADA
// REQ 3194: output real user name

// 2005-11-06 K.OHWADA
// BUG 3169: need to sanitaize $_SERVER['PHP_SELF']
// add _html_special_chars_url(), _conv_js()

// 2005-09-28 K.OHWADA
// change block.new.php & func.whatsnew.php to class

//=========================================================
// What's New Module
// class show block
// 2004/08/20 K.OHWADA
//=========================================================

// === class begin ===
if( !class_exists('whatsnew_show_block_handler') ) 
{

//=========================================================
// class whatsnew_show_block_handler
//=========================================================
class whatsnew_show_block_handler extends happy_linux_build_cache
{
    var $_DIRNAME;
    var $_DIR_MODULE;
    var $_URL_MODULE;

    var $_build;
    var $_system;

    var $_xoops_uid = 0;
    var $_cache_id  = null;
    var $_cache_id_guest = null;

    var $_TIME_PROHIBIT = 180;  // 180 sec
    var $_ICON_MAX_COL = 5;
    var $_MODE_BUILD   = 0;

    var $_DEBUG_FORCE  = false;

//---------------------------------------------------------
// constructor
//---------------------------------------------------------
function __construct( $dirname )
{
    $this->happy_linux_build_cache();

    $this->_build  =& whatsnew_get_handler('build_block', $dirname );
    $this->_system =& happy_linux_system::getInstance();

    $this->_DIRNAME    = $dirname;
    $this->_URL_MODULE = XOOPS_URL.      '/modules/'.$dirname;
    $this->_DIR_MODULE = XOOPS_ROOT_PATH.'/modules/'.$dirname;

    $this->_xoops_uid = $this->_system->get_uid();

// dirname + uid
    $this->_cache_id       = $dirname.'_u'.$this->_xoops_uid;
    $this->_cache_id_guest = $dirname.'_u0';

}

//=========================================================
// public
//=========================================================
function &show_block( $mode )
{
    $this->_MODE_BUILD = $mode;
    $template_file     = 'whatsnew_blk_'. $mode .'.html';
    $cache_time        = $this->_get_conf('block_cache_time');

    $block =& $this->_make_block_lang();
    $block['dirname'] = $this->_DIRNAME;
    $block['content'] = $this->_build_template( $template_file, $cache_time );

// send ping
    $this->_send_ping( $this->_get_conf('block_ping') );

    return $block;
}

//=========================================================
// private
//=========================================================
//--------------------------------------------------------
// build_template
//--------------------------------------------------------
function _build_template( $template_file, $cache_time )
{
    $template = $this->_get_template_filename( $template_file ) ;
    return $this->build_cache_by_cache_id(
        $this->_cache_id, $template, $cache_time, $this->_DEBUG_FORCE );
}

function _get_template_filename( $template_file )
{
    $theme_set = $GLOBALS['xoopsConfig']['theme_set'] ;

// in XOOPS themes directory
    $template_1 = XOOPS_THEME_PATH . '/' . $theme_set . '/templates/' . $template_file ;

// in templates/parts/theme_set
    $template_2 = $this->_DIR_MODULE.'/templates/parts/'. $theme_set . '/' . $template_file;

// in templates/theme_set
    $template_3 = $this->_DIR_MODULE.'/templates/'. $theme_set . '/' . $template_file;

// in templates/parts (default)
    $template_4 = $this->_DIR_MODULE.'/templates/parts/'. $template_file;

    if ( is_file($template_1) ) {
        return $template_1 ;
    } elseif ( is_file($template_2) ) {
        return $template_2 ;
    } elseif ( is_file($template_3) ) {
        return $template_3 ;
    }
    return $template_4 ;
}

function &_build_template_icon_list()
{
    $template = $this->_DIR_MODULE.'/templates/parts/whatsnew_icon_list.html';

// build template
    $tpl = new XoopsTpl();
    $tpl->assign( 'icon_max_col', $this->_ICON_MAX_COL );
    $tpl->assign( 'icon_list',    $this->build_icon_list() );
    $ret = $tpl->fetch( $template );
    return $ret;
}

//--------------------------------------------------------
// make language
//--------------------------------------------------------
function &_make_block_lang()
{
    $lang = array(
        'lang_mod'     => _WHATSNEW_BLOCK_MODULE,
        'lang_cat'     => _WHATSNEW_BLOCK_CATEGORY,
        'lang_title'   => _WHATSNEW_BLOCK_TITLE,
        'lang_user'    => _WHATSNEW_BLOCK_USER,
        'lang_hits'    => _WHATSNEW_BLOCK_HITS,
        'lang_replies' => _WHATSNEW_BLOCK_REPLIES,
        'lang_date'    => _WHATSNEW_BLOCK_DATE,
        'lang_more'    => _WHATSNEW_BLOCK_MORE,
    );
    return $lang;
}

//--------------------------------------------------------
// build_block
//--------------------------------------------------------
function &build_block_date()
{
    return $this->_build->build_block_date();
}

function &build_block_module()
{
    return $this->_build->build_block_module();
}

function &build_icon_list()
{
    return $this->_build->build_icon_list();
}

function _get_conf($key)
{
    return $this->_build->_get_conf($key);
}

function get_time_latest()
{
    return $this->_build->get_time_latest();
}

//=========================================================
// override into build_cache
//=========================================================
function _assign_cache( &$tpl )
{
    switch ( $this->_MODE_BUILD )
    {
        case 'date':
        case 'bop':
            $this->_assign_date( $tpl );
            break;

        case 'module':
            $this->_assign_module( $tpl );
            break;

        case 'main':
            $this->_assign_main( $tpl );
            break;

        case 'other':
        default:
            $this->_assign_other( $tpl );
            break;
    }
}

function _assign_date( &$tpl )
{
    $tpl->assign('lines',     $this->build_block_date() );
    $tpl->assign('icon_list', $this->_build_template_icon_list() );
    $tpl->assign('dirname',   $this->_DIRNAME );
    $tpl->assign( $this->_make_block_lang() );
}

function _assign_module( &$tpl )
{
    $tpl->assign('modules',   $this->build_block_module() );
    $tpl->assign('dirname',   $this->_DIRNAME );
    $tpl->assign( $this->_make_block_lang() );
}

function _assign_main( &$tpl )
{
    // dummy
}

function _assign_other( &$tpl )
{
    // dummy
}

//=========================================================
// send ping
//=========================================================
function _send_ping( $flag )
{
    if ( !$flag )
    {   return; }

    if ( ( $this->get_time_latest() - $this->_TIME_PROHIBIT ) > $this->_get_conf('ping_time') )
    {   return; }

    $this->_refresh_ping();
}

function _refresh_ping()
{
    include_once XOOPS_ROOT_PATH.'/modules/'.$this->_DIRNAME.'/api/api_ping.php';

// whatsnew_ping -> whatsnew_ping_handler
    $png = new whatsnew_ping_handler( $this->_DIRNAME );
    $ping->send_pings();
}

// --- class end ---
}

// === class end ===
}

?>
0

まず私はおそらく@boarderさんよりプログラムに関する知識はありますが、
このプログラムが何をしているか、何をすべきかは@boarderさんより分かっていません。
質問に対して基本的な解説やいくつかの例は出せるかもしれませんが、
何が正解なのかは@boarderさんが判断する必要があります。

クラスの継承というと、ざっくり説明するとRPGの上級職になるイメージです。
その例でエラーの説明をすると、
happy_linux_build_cacheクラスからwhatsnew_show_block_handlerクラスになったけどhappy_linux_build_cache()なんて覚えてないぜ」
ということです。

whatsnew_show_block_handlerクラスにはやはり見当たらないので、happy_linux_build_cacheクラスを確認する必要があります。

あと念の為確認したいのですが、
最初の回答例を試した時、この18行をそのまま4行の例に書き換えたということは無いでしょうか?

function __construct( $dirname )
{
    $this->happy_linux_build_cache();

    $this->_build  =& whatsnew_get_handler('build_block', $dirname );
    $this->_system =& happy_linux_system::getInstance();

    $this->_DIRNAME    = $dirname;
    $this->_URL_MODULE = XOOPS_URL.      '/modules/'.$dirname;
    $this->_DIR_MODULE = XOOPS_ROOT_PATH.'/modules/'.$dirname;

    $this->_xoops_uid = $this->_system->get_uid();

// dirname + uid
    $this->_cache_id       = $dirname.'_u'.$this->_xoops_uid;
    $this->_cache_id_guest = $dirname.'_u0';

}
0

happy_linux_build_cacheクラスを確認するどうしたらわかるのでしょうか?

@boarderさんに最初の回答例を試した時はparent::__construct();を追加しただけです。
コードは以下になります。

function __construct( $dirname )
{
    parent::__construct();

    $this->happy_linux_build_cache();

    $this->_build  =& whatsnew_get_handler('build_block', $dirname );
    $this->_system =& happy_linux_system::getInstance();

    $this->_DIRNAME    = $dirname;
    $this->_URL_MODULE = XOOPS_URL.      '/modules/'.$dirname;
    $this->_DIR_MODULE = XOOPS_ROOT_PATH.'/modules/'.$dirname;

    $this->_xoops_uid = $this->_system->get_uid();

// dirname + uid
    $this->_cache_id       = $dirname.'_u'.$this->_xoops_uid;
    $this->_cache_id_guest = $dirname.'_u0';

}
0

happy_linux_build_cacheクラスを確認するどうしたらわかるのでしょうか?

それが書かれたコードがどこかにあると思います。

@boarderさんに最初の回答例を試した時はparent::__construct();を追加しただけです。

追加しただけでは「未定義のhappy_linux_build_cache()を実行しようとしている」状況は変わらないので改善されないと思います。

まずはクラスについて理解するのが良いと思いますよ。
PHP: クラスとオブジェクト

0

blue32aさん

お返事ありがとうございます。

プログラミングは素人で、正直言って読んでみてもチンプンカンプンの状態ですが
もうちょっと読んでみます。

build_cache.phpというものを見つけてその中に15行目にhappy_linux_build_cacheを
クラスを定義しているところがあったので、貼り付けてみます。

この中に答えがあるのでしょうか?

<?php
// $Id: build_cache.php,v 1.1 2010/11/07 14:59:20 ohwada Exp $

// 2007-10-10 K.OHWADA
// divid from happy_linux_build_rss

//=========================================================
// Happy Linux Framework Module
// 2006-09-01 K.OHWADA
//=========================================================

//=========================================================
// class builder base
//=========================================================
class happy_linux_build_cache
{

// for reserve, not use here
    var $_DIRNAME    = null;
    var $_tepmlate   = null;
    var $_cache_time = 0;

//---------------------------------------------------------
// constructor
//---------------------------------------------------------
function __construct()
{
    // dummy
}

public static function &getInstance()
{
    static $instance;
    if (!isset($instance)) 
    {
        $instance = new happy_linux_build_cache();
    }
    return $instance;
}

//=========================================================
// public
//=========================================================
function build_cache( $template, $cache_time=0, $flag_force=false )
{

// build template
    $tpl = new XoopsTpl();

// use cache
    if ( !$flag_force && ($cache_time > 0) )
    {
// 2: use cache time in every templates
        $tpl->xoops_setCaching(2);
        $tpl->xoops_setCacheTime($cache_time);
    }

    if ( $flag_force || ($cache_time == 0) || !$tpl->is_cached($this->_template) )
    {
        $this->_assign_cache( $tpl );
    }

    $ret = $tpl->fetch( $template );
    return $ret;
}

function build_cache_by_cache_id( $cache_id, $template, $cache_time=0, $flag_force=false )
{

// build template
    $tpl = new XoopsTpl();

// use cache
    if ( !$flag_force && ($cache_time > 0) )
    {
// 2: use cache time in every templates
        $tpl->xoops_setCaching(2);
        $tpl->xoops_setCacheTime($cache_time);
    }

    if ( $flag_force || ($cache_time == 0) || !$tpl->is_cached($template, $cache_id) )
    {
        $this->_assign_cache( $tpl );
    }

    $ret = $tpl->fetch( $template, $cache_id );
    return $ret;
}

function rebuild_cache( $template )
{
    $this->clear_compiled_tpl( $template );
    $this->clear_cache( $template );
    $ret = $this->build_cache( $template, 0, true );
    return $ret;
}

function clear_cache( $template )
{
    $tpl = new XoopsTpl();
    $tpl->clear_cache( $template );
}

function clear_cache_by_cache_id( $cache_id, $template )
{
    $tpl = new XoopsTpl();
    $tpl->clear_cache( $template, $cache_id );
}

// dir doesn't include XOOPS_ROOT_PATH
function clear_compiled_tpl_by_dir( $dir )
{
    $class_dir = happy_linux_dir::getInstance();
    $dir =  $class_dir->strip_slash_from_tail( $dir );
    $arr =& $class_dir->get_files_in_dir( $dir, 'html' );

    foreach ($arr as $file)
    {
        if ( $file == 'index.html' )
        {   continue;   }

        $this->clear_compiled_tpl( XOOPS_ROOT_PATH.'/'.$dir.'/'.$file );
    }
}

function clear_compiled_tpl( $template )
{
    $tpl = new XoopsTpl();
    $tpl->clear_compiled_tpl( $template );
}

//--------------------------------------------------------
// set param
//--------------------------------------------------------
function set_dirname($value)
{
    $this->_DIRNAME = $value;
}

function set_template($value)
{
    $this->_tepmlate = $value;
}

function set_cache_time($value)
{
    $this->_cache_time = intval($value);
}

function get_cache_time()
{
    return $this->_cache_time;
}

//=========================================================
// over ride
//=========================================================
function _assign_cache( &$tpl )
{
    // dummy
}

// --- class end ---
}

?>
0

拝見しましたがhappy_linux_build_cacheクラスの中にもhappy_linux_build_cache()ありません。

$this->happy_linux_build_cache();

おそらくこれはhappy_linux_build_cacheクラスのコンストラクタを実行するのが目的であり、
PHP5.6では問題なかったがPHP7.3では実行できなくなった、
ということだと思います。

これに関しては私の最初2回目の回答に関連します。

0

blue32aさん

クラスとオブジェクトのマニュアルを読みましたが、私の頭では理解ができず、修復を諦めようかと思案中です。

ちなみに前回貼り付けたbuild_cache.phpの36行目のhappy_linux_build_cache();は関係のない処理なのでしょうか?

$instance = new happy_linux_build_cache();
0

いきなりクラスやオブジェクトついて学習しても理解は難しいでしょう。
差し出がましいかもしれませんが、業務上の都合があるならば専門のコンサルタントに依頼するのが良いと思います。ここはあくまで技術共有の場なので。

ちなみに前回貼り付けたbuild_cache.phpの36行目のhappy_linux_build_cache();は関係のない処理なのでしょうか?

これまで見た情報からは、関係ないと考えてます。

0

blue32aさん

色々アドバイスいただきありがとうございました。

XOOPSも最近使っていない方も多く、検索してもページが無くなったりして調べることも難しくなっています。

今回のモジュールは、使わないようにします。

0

Your answer might help someone💌