This topic is locked

PHP 8.1 Undefined constant problem

2/23/2024 10:45:15 AM
PHPRunner General questions
aadham author

Hi All

I have a task assignment page (Custom View) that started throwing "Fatal error: Uncaught Error: Undefined constant" error since my hosting upgraded to PHP 8.1.

Using latest PHPRunner 10.91 Build 41619

Here's the error message:

Fatal error: Uncaught Error: Undefined constant "order_det_id" in E:\xampp\htdocs\app_new\include\my_tasks_events.php:661 Stack trace: #0 E:\xampp\htdocs\app_new\classes\editpage.php(1433): eventclass_my_tasks->AfterEdit(Array, '( ( `tasks_id`=...', Array, Array, false, Object(EditPage)) #1 E:\xampp\htdocs\app_new\classes\editpage.php(1364): EditPage->callAfterEditEvent() #2 E:\xampp\htdocs\app_new\classes\editpage.php(289): EditPage->processDataInput() #3 E:\xampp\htdocs\app_new\my_tasks_edit.php(106): EditPage->process() #4 {main} thrown in E:\xampp\htdocs\app_new\include\my_tasks_events.php on line 661

And here's the code is says is the culprit:

$fullname=DBLookup("SELECT concat(employees.emp_firstname,' ',emp_familyname) FROM tasks INNER JOIN employees ON tasks.emp_id = employees.emp_id WHERE tasks.order_det_id =".$values['order_det_id']);

Can anyone please shed some light on what/where the mistake is?

Thank you

fhumanes 2/24/2024

Hello,

In this article I explained the importance of using PHP 8.1: https://fhumanes.com/blog/cambio-del-portal-a-php-8-1/

And also, the problems I had.

The main problem is:

$valor = $values[id]; // fIt worked at PHP 7.4 and not in PHP 8.1
$valor = $values['id']; // Always correct

I think it's the problem you have.

Greetings,
fernando

aadham author 2/24/2024

Hi Fernando,

As you can see in the line of code I've included that I'm using single quotes (".$values['order_det_id']);), but I still get the error message.

fhumanes 2/25/2024

Hi,
I'm sure that's the problem.

Check the error line.

Greetings

aadham author 2/25/2024

Hi Fernando

I understand what you're saying about the single quotes, but as you can see in the line of code, that has already been fixed across the entire code of all events in the page , yet the error isn't going away.

C
cristi 2/26/2024

@fernando: it worked in php 7 but I am pretty sure that you had warnings like: Warning: Use of undefined constant id - assumed 'id' (this will throw an Error in a future version of PHP).

@aadham: double check your code - the error may be in that line but it could had been originated from other piece of code....
Also maybe your host did not updated all the php files?

Undefined constant means one of three things:

  1. not using define() or const when declaring a constant - unlikely in your case
  2. not using $ symbol when calling variables
  3. not using quotes around strings

In older php version you had only warnings, in php 8 it's full stop and thrown error.

admin 2/27/2024

My guess is that the error is coming from the different line of code. As Fernando rightfully mentions, this error is most likely coming from the missing quote.