Code PHP Fatal error: Uncaught ArgumentCountError: DateTime::__construct() expects at most 2 parameters, 3 given (I do not see why?)

Here is the original core file https://github.com/phpbb/phpbb-core/blob/master/user.php Looks the same as mine...

From symfony

/**
 * Sets the Date header.
 *
 * @return $this
 *
 * @final since version 3.2
 */
public function setDate(\DateTime $date)
{
    $date->setTimezone(new \DateTimeZone('UTC'));
    $this->headers->set('Date', $date->format('D, d M Y H:i:s').' GMT');

    return $this;
}

This was running fine and then all a sudden it crashed. [16-Sep-2022 15:21:12 UTC] PHP Fatal error: Uncaught ArgumentCountError: DateTime::__construct() expects at most 2 parameters, 3 given in /home/groomlake/public_html/engine/user.php:629

I'm looking but I can't see what is causing it. Can someone point it out? Maybe I have been awake too long and I do not see it...

/**
* Format user date
*
* @param int $gmepoch unix timestamp
* @param string $format date format in date() notation. | used to indicate relative dates, for example |d m Y|, h:i is translated to Today, h:i.
* @param bool $forcedate force non-relative date format.
*
* @return mixed translated date
*/


function format_date($gmepoch, $format = false, $forcedate = false)
{
    global $engine_dispatcher;
    static $utc;

    if (!isset($utc))
    {
        $utc = new \DateTimeZone('UTC');
    }

    $format_date_override = false;
    $function_arguments = func_get_args();
    /**
    * Execute code and/or override format_date()
    *
    * To override the format_date() function generated value
    * set $format_date_override to new return value
    *
    * @event core.user_format_date_override
    * @var DateTimeZone utc Is DateTimeZone in UTC
    * @var array function_arguments is array comprising a function's argument list
    * @var string format_date_override Shall we return custom format (string) or not (false)
    * @since 3.2.1-RC1
    */
    $vars = array('utc', 'function_arguments', 'format_date_override');
    extract($engine_dispatcher->trigger_event('core.user_format_date_override', compact($vars)));

    if (!$format_date_override)
    {
        /*error is on the following  line*/         
        $time = new $this->datetime($this, '@' . (int) $gmepoch, $utc);
        
        $time->setTimezone($this->create_timezone());

        return $time->format($format, $forcedate);
    }
    else
    {
        return $format_date_override;
    }
}

Upvotes: 0

Views: 768

Answers (1)

Code Buzzard
Code Buzzard

Reputation: 46

You have a problem with your dynamic namespace system. More than likely you have changed the name of a dynamic global namespace.

Backtrack, go back, and restore your changes before you changed your dynamic namespace name. i.e. (engine)

I looked at phpBB and I can see your namespace is (engine) instead of the PhpBB original dynamic namespace name which was (phpbb). That is where your problem is stemming from.

You also may have changed your directory depth somewhere and the dynamic namespace function will cause the pages to not load.

phpBB is one of the very few that have a dynamic namespace system and it is a bit complicated for the average person to traverse in their mind.

Upvotes: 1

Related Questions