PDA

View Full Version : PHP 7 To PHP 8 Issue


BulliM
10-27-2021, 05:30 PM
Since quite a while I get php 7.3 warnings in Nginx error.log:

FastCGI sent in stderr: "PHP message: PHP Warning: Use of undefined constant assets - assumed 'assets' (this will throw an Error in a future version of PHP) in /var/www/*******/includes/vb5/template.php(404) : eval()'d code on line 256


As long as it works I ignored that. But when I update PHP to version 8, the sub site is no longer available. Seems that warning occurs an error now.

In my code I cannot find any error. The problem seems to result in a loop of my (simplified) code:


foreach($variables as $variable)
{
$item = vB::getDbAssertor()->getRow('APINAME:TABLENAME', array('FIELDNAME' => $variable));
$var[$i]['FIELD'][$y] = $item['FIELD'];
}


Don't really know, what php8 needs to work at this point. Has anyone an idea?

shka
10-28-2021, 01:26 PM
https://www.php.net/manual/de/migration80.incompatible.php


A number of warnings have been converted into Error exceptions:
...
Attempting to access unqualified constants which are undefined. Previously, unqualified constant accesses resulted in a warning and were interpreted as strings.


Deine Variablenbezeichnungen sind grausam nichtssagend (var, variables, variable, y, i). Welche davon kann den Wert 'assets' annehmen?

Your variables are cruelly named. Which of them can get the value 'assets'?

BulliM
10-28-2021, 11:47 PM
https://www.php.net/manual/de/migration80.incompatible.php
Thanks for that. Will check that.

Your variables are cruelly named. Which of them can get the value 'assets'?
Seems not important, because any line like...
$var[$i]['FIELD'][$y] = $item['FIELD'];
...in my code, results in this error.

Only if all those (five) lines excluded, my code is running. But probably these lines aren't the problem. At the moment I really don't know, what is going on.

--------------- Added 1635476154 at 1635476154 ---------------

SOLVED

I've solved that. Error was in template.

This code...
<vb:if condition="$val.assets >0">...</vb:if>
...results in that error.

I solved that by doing...

{vb:set assets, {vb:var val.assets}}
<vb:if condition="$assets >0">...</vb:if>
...what works with PHP8. I have no errors anymore. :)

delicjous
10-29-2021, 05:41 AM
You could use $val['assets'] directly in your if condition.

BulliM
10-29-2021, 12:01 PM
You could use $val['assets'] directly in your if condition.
I tried yesterday, but this doesn't work.

delicjous
10-30-2021, 03:10 AM
I tried yesterday, but this doesn't work.

Dann wei? ich auch nicht?

Then shka is right and we need more input. But if it is working it is ok I think