You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PHP构造函数弃用报错:POMO_Reader构造函数问题求助

Fixing the POMO_Reader Constructor Deprecation Error

Hey there, let's work through this deprecation error together. The issue here is super common when upgrading PHP versions—older code that uses class-name-as-constructor syntax gets flagged because PHP 7.0+ deprecated that behavior, and it'll be removed entirely in future versions.

First, let's clear up the mistake you made earlier: renaming the constructor to class() isn't the right move. PHP's standard constructor method (for PHP 5.0+) is __construct() (note the two underscores at the start). That's the key fix here.

Here's the corrected code for your POMO_Reader class:

if ( !class_exists( 'POMO_Reader' ) ):
class POMO_Reader {
    var $endian = 'little';
    var $_post = '';
    var $_pos = 0;
    var $is_overloaded = false;

    function __construct() {
        $this->is_overloaded = ((ini_get("mbstring.func_overload") & 2) != 0) && function_exists('mb_substr');
        $this->_pos = 0;
    }
}
endif;

Let's break down the steps to make sure this sticks:

  • Fix the constructor name: Replace function POMO_Reader() with function __construct(). This is the modern, PHP-standard way to define a constructor, and it'll work across all supported PHP versions (5.3+).
  • Explicitly declare class variables: I added explicit declarations for $_pos and is_overloaded at the top of the class. While PHP lets you create variables on the fly, declaring them upfront makes the code clearer and avoids any odd edge cases with variable scope.
  • Clear caches: If you still see the error after modifying the file, chances are your server is caching the old code. Clear any OPcache, Joomla page cache, or server-level caches you have enabled—sometimes you even need to restart your PHP service to get the changes to take effect.
  • Double-check your PHP version: If switching PHP versions didn't help, make sure you're on a version that supports __construct() (PHP 5.3 or newer). PHP 4 is long end-of-life, so you shouldn't be using it anyway, but it's worth confirming.
  • Check related files: The POMO framework has other classes (like POMO_Writer or subclasses of POMO_Reader) that might have the same deprecated constructor syntax. If you still see errors after fixing this class, hunt down those other files and apply the same __construct() fix.

That should resolve the deprecation error for you. Let me know if you run into any snags!

内容的提问来源于stack exchange,提问作者Gundo Tshimauswu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 08:21:47