application icon indicating copy to clipboard operation
application copied to clipboard

Combination of nette/application 3.1.7 and nette/utils 3.2.7 triggers a deprecation error in Tracy

Open Marian-Kechlibar opened this issue 3 years ago • 6 comments

Version: 3.1.7

Bug Description

When using nette/application 3.1.7 and nette/utils 3.2.7 together, Tracy shows a deprecation error in SmartObject:

User Deprecated

Nette\Application\UI\Presenter::getContext() is deprecated, use dependency injection.

and the file where the error is being triggered is:

[vendor\nette\utils\src\SmartObject.php:80], namely

: if ($prop & 0b0100) { // return by reference 78: return $this->$m(); 79: } else { 80: $val = $this->$m(); 81: return $val; 82: }

Marian-Kechlibar avatar Aug 24 '22 08:08 Marian-Kechlibar

The getContext() method is deprecated (for a long time) and since nette/application version 3.1 it throws a notice, because it will be removed in 4.0.

I don't understand the relation with SmartObject. What do you mean by file where the error is being triggered? Because it is triggered here https://github.com/nette/application/blob/e94316c0a095b87aeb7f291adc08679bbb0d95ec/src/Application/UI/Presenter.php#L1421.

dg avatar Aug 24 '22 14:08 dg

By using Nette\SmartObject, you should normally get an error when accessing an undeclared property. That is the expected behavior.

But when I use nette/application 3.1.7 and nette/utils 3.2.7 side by side, and I actually make the mistake of using an undeclared property in an object that uses SmartObject, instead of the expected error, a deprecation error regarding getContext is triggered.

Marian-Kechlibar avatar Aug 24 '22 15:08 Marian-Kechlibar

Did you use the $this->context variable? Because it is "declared", it just throws this warning. https://github.com/nette/application/blob/e94316c0a095b87aeb7f291adc08679bbb0d95ec/src/Application/UI/Presenter.php#L28

dg avatar Aug 24 '22 15:08 dg

Well that is the weird thing. I never use this variable or getContext() in my code. I searched my codebase via PHPStorm and there just isn't any ->context or ->getContext() use at all.

I don't understand the relation with SmartObject either. It just started randomly happening once I updated my nette libraries. I "solved" it for now by removing the deprecation warning, which is not really a solution, but at least allows me to work right now.

Did you use the $this->context variable? Because it is "declared", it just throws this warning.

Marian-Kechlibar avatar Aug 25 '22 09:08 Marian-Kechlibar

An example of the exception:

ErrorException: Nette\Application\UI\Presenter::getContext() is deprecated, use dependency injection. in C:\wamp64\www\kraken-control\vendor\nette\application\src\Application\UI\Presenter.php:1421
Stack trace:
#0 C:\wamp64\www\kraken-control\vendor\tracy\tracy\src\Tracy\Debugger\Debugger.php(380): Tracy\DevelopmentStrategy->handleError(16384, 'Nette\\Applicati...', 'C:\\wamp64\\www\\k...', 1421, NULL)
#1 [internal function]: Tracy\Debugger::errorHandler(16384, 'Nette\\Applicati...', 'C:\\wamp64\\www\\k...', 1421)
#2 C:\wamp64\www\kraken-control\vendor\nette\application\src\Application\UI\Presenter.php(1421): trigger_error('Nette\\Applicati...', 16384)
#3 C:\wamp64\www\kraken-control\vendor\nette\utils\src\SmartObject.php(80): Nette\Application\UI\Presenter->getContext()
#4 xdebug://debug-eval(1): Nette\ComponentModel\Component->__get('context')
#5 C:\wamp64\www\kraken-control\app\Module\Basic\Presenters\SubmitPresenter.php(70): unknown()
#6 [internal function]: App\Module\Basic\Presenters\SubmitPresenter->renderDefault()
#7 C:\wamp64\www\kraken-control\vendor\nette\application\src\Application\UI\Component.php(120): ReflectionMethod->invokeArgs(Object(App\Module\Basic\Presenters\SubmitPresenter), Array)
#8 C:\wamp64\www\kraken-control\vendor\nette\application\src\Application\UI\Presenter.php(239): Nette\Application\UI\Component->tryCall('renderdefault', Array)
#9 C:\wamp64\www\kraken-control\vendor\nette\application\src\Application\Application.php(163): Nette\Application\UI\Presenter->run(Object(Nette\Application\Request))
#10 C:\wamp64\www\kraken-control\vendor\nette\application\src\Application\Application.php(90): Nette\Application\Application->processRequest(Object(Nette\Application\Request))
#11 C:\wamp64\www\kraken-control\www\index.php(10): Nette\Application\Application->run()
#12 {main}

None of my files involved, notably the SubmitPresenter, does use context() explicitly. The line 70 of SubmitPresenter looks like this:

if (array_key_exists(JsonHeaders::MESSAGE_TYPE_PING_RESPONSE, $this->replies))

so I suspect that the problem is triggered by the SmartObject checking whether $this->replies is indeed a correctly named property of SubmitPresenter (it is).

Marian-Kechlibar avatar Aug 26 '22 06:08 Marian-Kechlibar

The problem is in point #4 #4 xdebug://debug-eval(1): Nette\ComponentModel\Component->__get('context'), maybe some kind of watched variable in the IDE?

dg avatar Aug 28 '22 21:08 dg

It is PhpStorm issue https://youtrack.jetbrains.com/issue/WI-69782/Debugger-invokes-magic-methods-when-stepping-for-no-reason

dg avatar Nov 18 '22 01:11 dg