Fixed mistake with using $this in a static function

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pifagor created an issue. See original summary.

pifagor’s picture

Status: Active » Needs review
FileSize
2.99 KB
alex_optim’s picture

Looks good.

hass’s picture

Status: Needs review » Postponed (maintainer needs more info)

This was changed in last month and has not caused any issues. What is wrong here?

pifagor’s picture

Status: Postponed (maintainer needs more info) » Needs review

You use $this in a static method, for example protected static function validateCreateFieldValue use $this->t('The value of
More info here - http://php.net/manual/en/language.oop5.static.php

Because static methods are callable without an instance of the object created, the pseudo-variable $this is not available inside the method declared as static.

  • hass committed 860761f on 8.x-3.x
    Issue #2977908 by pifagor: Fixed mistake with using $this in a static...

  • hass committed 40ef523 on 8.x-2.x authored by pifagor
    Issue #2977908 by pifagor: Fixed mistake with using $this in a static...
hass’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

Anitche ekpereamaka’s picture

hello am having this issue

public static function createFromGlobals(): static
{
$request = self::createRequestFromFactory($_GET, $_POST, [], $_COOKIE, $_FILES, $_SERVER);

if (str_starts_with($request->headers->get('CONTENT_TYPE', ''), 'application/x-www-form-urlencoded')
&& \in_array(strtoupper($request->server->get('REQUEST_METHOD', 'GET')), ['PUT', 'DELETE', 'PATCH'])
) {
parse_str($request->getContent(), $data);
$request->request = new InputBag($data);
}

return $request;