0

I'm currently doing a major upgrade on a Nette based website. We have multiple custom DI extensions, custom ORM and use the Nittro UI framework. So the upgrade is quite involved. Going from PHP 7.2 -> 8.4 and Nette 2.2 -> 3.2. I have been able to solve tens of errors, but not this one.

I get Non-static method Nette\Http\RequestFactory::fromGlobals() cannot be called statically error whenever I try to load a page. This error (according to Tracy) seems to be coming from the following segment of the auto-generated DI container:

public function createServiceHttp__request(): Nette\Http\Request
{
    return Nette\Http\RequestFactory::fromGlobals();
}

The thing is, I don't create the service anywhere, it's Nette's - and I guess, that it comes from Nette\Bridges\HttpDI\HttpExtension line 56:

$request = $builder->addDefinition($this->prefix('request'))
            ->setFactory('@Nette\Http\RequestFactory::fromGlobals');

I have tried going down ->setFactory - but I can't even find it on the Definition class. More over I probably have misconfigured my debugger as it won't stop on breakpoints in the cached container.

How do I fix this? Can I perhaps replace the http.request service with one of my own?

Thanks in advace!

This is part of my composer.json:

    "require": {
        "php": ">=8.4",
        "ext-pdo": "*",
        "ext-pdo_firebird": "*",
        "ext-curl": "*",
        "ext-json": "*",
        "ext-libxml": "*",
        "ext-simplexml": "*",
        "nette/application": "3.2.*",
        "nette/bootstrap": "3.2.*",
        "nette/forms": "3.2.*",
        "nette/http": "3.3.*",
        "nette/security": "3.2.*",
        "nette/di": ">=3.2",
        "nette/caching": "3.3.*",
        "nette/robot-loader": ">=4",
        "tracy/tracy": ">=3",
        "nittro/nette-bridges": "*",
        "symfony/console": ">=7.3",
        "latte/latte": ">=3",
        "jahudka/porm": "^0.1.0",
        "jahudka/component-events": "*"
    }

(some of the things are linked from forked repos, not the public versions)

0

2 Answers 2

1

Downgrading to "nette/di": "3.2.4"solved the issue. In my case, i just had to set "prefer-stable": true in composer.json.

The problem turned out to be in Nette\DI itself. It was quite a ride to debug, because the problem only manifests itself, when running PHP without a debugger! With a debugger enabled, the container gets created with the proper function, which is supposed to be:

public function createServiceHttp__request(): Nette\Http\Request
{
    return $this->getService('http.requestFactory')->fromGlobals();
}

Thanks to user @rixafy on the Nette Discord server who proposed downgrading as the solution.

Sign up to request clarification or add additional context in comments.

Comments

0

I managed to track down where setFactory is defined.

https://github.com/nette/di/blob/master/src/DI/Definitions/ServiceDefinition.php#L62

https://github.com/nette/di/blob/master/src/DI/Definitions/Statement.php#L34

https://github.com/nette/di/blob/master/src/DI/Definitions/Reference.php#L39

Maybe with this will provide you the information you need to finish debugging the issue. I'm not a Nette user myself so it doesn't really tell me much but it might be just what you need.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.