Topic: PHP 7.4 bug

Unparenthesized `a ? b : c ? d : e` is deprecated. Use either `(a ? b : c) ? d : e` or `a ? b : (c ? d : e)` in file: gl/includes/db/gl_db_trans.inc at line 464

www.boxygen.pk

Re: PHP 7.4 bug

Add parenthesis to the first condition.
Replace:

$reg_type = in_array($trans_type, array(ST_SUPPINVOICE, ST_SUPPCREDIT)) ? TR_OUTPUT
                : in_array($trans_type, array(ST_SALESINVOICE, ST_CUSTCREDIT)) ? TR_INPUT : null;

with:

$reg_type = (in_array($trans_type, array(ST_SUPPINVOICE, ST_SUPPCREDIT)) ? TR_OUTPUT
                : in_array($trans_type, array(ST_SALESINVOICE, ST_CUSTCREDIT))) ? TR_INPUT : null;

I have also noted more deprecation errors on php 7.4. I dont know how FA team intends to maintain compatibility to new php versions.

Re: PHP 7.4 bug

@detkenn if you see more depreciation , do list them, some one will find solution to it.

Subscription service based on FA
HRM CRM POS batch Themes

Re: PHP 7.4 bug

The parenthesis should be added to the second condition as it is a fallback. First choice Output, then Input and last NULL.

Lines 464-465 of file gl/includes/db/gl_db_trans.inc:

        $reg_type = in_array($trans_type, array(ST_SUPPINVOICE, ST_SUPPCREDIT)) ? TR_OUTPUT
                : in_array($trans_type, array(ST_SALESINVOICE, ST_CUSTCREDIT)) ? TR_INPUT : null;

should be:

        $reg_type = in_array($trans_type, array(ST_SUPPINVOICE, ST_SUPPCREDIT)) ? TR_OUTPUT
                : (in_array($trans_type, array(ST_SALESINVOICE, ST_CUSTCREDIT)) ? TR_INPUT : null);

It is properly coded in line 86 of includes/JsHttpRequest.php.

@joe: can implement this and check for others.

Re: PHP 7.4 bug

Array and string offset access syntax with curly braces is deprecated in file: ...../reporting/includes/tcpdf.php at line 9305

www.boxygen.pk

Re: PHP 7.4 bug

An example of curly brace correction is available in another project's commit.

A migration script to automatically make these changes is here.

This is an issue since 2008 when both square and curly brackets were used interchangeably for arrays and string elements though it was the intention to sue them for separate purposes as explained at:

https://wiki.php.net/rfc/deprecate_curly_braces_array_access

Though currently in PHP 7.4, only the square braces can be used to initialise arrays and also assign to them values, the curly braces can generally be used everywhere else where the square bracket is used.

Other threads elsewhere that refer to this problem are at:
https://github.com/squizlabs/PHP_CodeSniffer/issues/2558
https://stackoverflow.com/questions/59158548/array-and-string-offset-access-syntax-with-curly-braces-is-deprecated

Re: PHP 7.4 bug

Please try the attached fix on both PHP 7.4 and PHP5.x as well.

@joe: please verify and take in the fix into the core ensuring backwards compatibility.

Post's attachments

tcpdf_php74_fix.zip 148.3 kb, 7 downloads since 2020-07-04 

You don't have the permssions to download the attachments of this post.

Re: PHP 7.4 bug

This is good reporting. Let us continue to use this thread for new php version problems.

I will occasionally try to fix the problems with backward compatibility.

Joe

Re: PHP 7.4 bug

Some of the compatibility problems have now been fixed and committed to 2.4.8 stable repo.

The following compatibility bugs still remains for fixing:

Function get_magic_quotes_gpc() is deprecated in file: C:\wamp3\www\account24\includes\session.inc at line 315

implode(): Passing glue string after array is deprecated. Swap the parameters in file: C:\wamp3\www\account24\includes\ui\ui_lists.inc at line 161

Trying to access array offset on value of type null in file: C:\wamp3\www\account24\reporting\includes\tcpdf.php at line 1127

chr() expects parameter 1 to be int, string given in file: C:\wamp3\www\account24\reporting\includes\tcpdf.php at line 3525

Joe

Re: PHP 7.4 bug

@itronics commit should fix it.

Re: PHP 7.4 bug

Beginning with PHP 7.4.8 (perhaps earlier), php started announcing the following error:

Trying to access array offset on value of type bool ...

Mostly the error can be ignored, but it does indicate improper coding in FA, and possibly bugs.  I haven't done much investigation, but here are a few suggested PHP 7.4.8 fixes to FA (and I am sure there will be many more):

--- a/core/gl/gl_journal.php
+++ b/core/gl/gl_journal.php
@@ -149,7 +149,7 @@ function create_cart($type=0, $trans_no=0)
         {
             $net_sum = 0;
             foreach($cart->gl_items as $gl)
-                if (!is_tax_account($gl->code_id) && !is_subledger_account($gl->code_id, $gl->person_id))
+                if (!is_tax_account($gl->code_id) && !is_subledger_account($gl->code_id))
                     $net_sum += $gl->amount;
 
             $ex_net = abs($net_sum) - array_sum($tax_info['net_amount']);
diff --git a/core/gl/includes/db/gl_db_accounts.inc b/core/gl/includes/db/gl_db_accounts.inc
index 53eb5a9..dc60c13 100644
--- a/core/gl/includes/db/gl_db_accounts.inc
+++ b/core/gl/includes/db/gl_db_accounts.inc
@@ -224,7 +224,7 @@ function is_subledger_account($account)
 
     $result = db_query($sql,"Couldn't test AR/AP account");
     $myrow = db_fetch_row($result);
-    return $myrow[0];
+    return $myrow == false ? 0 : $myrow[0];
 }
 
 function get_subaccount_data($code_id, $person_id)
diff --git a/core/includes/references.inc b/core/includes/references.inc
index a928c7e..027aafd 100644
--- a/core/includes/references.inc
+++ b/core/includes/references.inc
@@ -227,7 +227,7 @@ class references
             return false;
 
         $result = db_fetch_row($result);
-        return $result[0];
+        return $result == false ? false : $result[0];
     }
 
     function is_new_reference($ref, $type, $trans_no=0)
diff --git a/core/includes/ui/items_cart.inc b/core/includes/ui/items_cart.inc
index 2fe92da..3c91f0b 100644
--- a/core/includes/ui/items_cart.inc
+++ b/core/includes/ui/items_cart.inc
@@ -144,8 +144,8 @@ class items_cart
         $this->gl_items[$index]->code_id = $code_id;
         $this->gl_items[$index]->person_id = $person_id;
 
-        $gl_type = is_subledger_account($code_id, $person_id);
-        if ($gl_type)
+        $gl_type = is_subledger_account($code_id);
+        if ($person_id != null && $gl_type)
         {
             $this->gl_items[$index]->person_type_id = $gl_type > 0 ? PT_CUSTOMER : PT_SUPPLIER;
             $data = get_subaccount_data($code_id, $person_id);
@@ -263,7 +263,7 @@ class items_cart
 
         foreach($this->gl_items as $gl)
         {
-            if ($person_type = is_subledger_account($gl->code_id, $gl->person_id))
+            if ($person_type = is_subledger_account($gl->code_id))
             {
                 $tax_info['person_type'] = $person_type < 0 ? PT_SUPPLIER : PT_CUSTOMER;
                 $tax_info['person_id'] = $gl->person_id;
@@ -520,8 +520,8 @@ class gl_item
 
         $this->code_id = $code_id;
         $this->person_id = $person_id;
-        $gl_type = is_subledger_account($code_id, $person_id);
-        if ($gl_type)
+        $gl_type = is_subledger_account($code_id);
+        if ($person_id != null  && $gl_type)
         {
             $this->person_type_id = $gl_type > 0 ? PT_CUSTOMER : PT_SUPPLIER;
             $data = get_subaccount_data($code_id, $person_id);
diff --git a/core/sales/includes/db/sales_order_db.inc b/core/sales/includes/db/sales_order_db.inc
index fcc19fd..17952e3 100644
--- a/core/sales/includes/db/sales_order_db.inc
+++ b/core/sales/includes/db/sales_order_db.inc
@@ -648,5 +648,5 @@ function last_sales_order_detail($order, $field)
 
         $last_query=db_query($sql, "Could not retrieve last order detail");
         $row = db_fetch_row($last_query);
-        return $row[0];
+        return $row == false ? false : $row[0];
 }
diff --git a/core/sales/includes/sales_db.inc b/core/sales/includes/sales_db.inc
index 6ff05f1..02cbaaf 100644
--- a/core/sales/includes/sales_db.inc
+++ b/core/sales/includes/sales_db.inc
@@ -231,6 +231,7 @@ function read_sales_trans($doc_type, $trans_no, &$cart)
     } else {
         // read header data from first document
         $myrow = get_customer_trans($trans_no[0],$doc_type);
+        $debtor_no = $myrow['debtor_no'];
         if (count_array($trans_no)>1)
             $cart->trans_no = get_customer_trans_version($doc_type, $trans_no);
         else
@@ -238,7 +239,7 @@ function read_sales_trans($doc_type, $trans_no, &$cart)
 
         $cart->set_sales_type($myrow["tpe"], $myrow["sales_type"], $myrow["tax_included"],0);
 
-        $cart->set_customer($myrow["debtor_no"], $myrow["DebtorName"],
+        $cart->set_customer($debtor_no, $myrow["DebtorName"],
             $myrow["curr_code"], $myrow["discount"], $myrow["payment_terms"]);
 
         $cart->set_branch($myrow["branch_code"], $myrow["tax_group_id"],
@@ -279,7 +280,7 @@ function read_sales_trans($doc_type, $trans_no, &$cart)
                     @$myrow["src_id"]);
             }
         }
-        $cart->prepayments = get_payments_for($trans_no, $doc_type, $myrow["debtor_no"]);
+        $cart->prepayments = get_payments_for($trans_no, $doc_type, $debtor_no);
 
     } // !newdoc
 
diff --git a/core/sales/includes/ui/sales_order_ui.inc b/core/sales/includes/ui/sales_order_ui.inc
index babf8f2..7172dff 100644
--- a/core/sales/includes/ui/sales_order_ui.inc
+++ b/core/sales/includes/ui/sales_order_ui.inc
@@ -400,7 +400,7 @@ function display_order_header(&$order, $editable, $date_text)
     if (($order->pos['cash_sale'] || $order->pos['credit_sale']) 
         && !$order->is_started()) {
          // editable payment type 
-        if (get_post('payment') !== $order->payment) {
+        if (isset($_POST['payment']) && $_POST['payment'] !== $order->payment) {
             $order->payment = get_post('payment');
             $order->payment_terms = get_payment_terms($order->payment);
             $order->due_date = get_invoice_duedate($order->payment, $order->document_date);

Re: PHP 7.4 bug

Thanks @Braath Waate,

Really nice of you to catch these nasty errors. It was really frustating to have come from a compiled language like C/C++ many years ago to the sloppy PHP at that time. During the PHP period we have learnt a lot about this language.
But, nice to get help with these errors. Will be committed asap this day.

/Joe

Re: PHP 7.4 bug

Also,

diff --git a/core/purchasing/includes/db/grn_db.inc b/core/purchasing/includes/db/grn_db.inc
index d2fbd7f..0820fb3 100644
--- a/core/purchasing/includes/db/grn_db.inc
+++ b/core/purchasing/includes/db/grn_db.inc
@@ -17,15 +17,14 @@ function update_average_material_cost($supplier, $stock_id, $price, $qty, $date,
        // save a couple of db calls like get_supplier()
        
        $supp = get_supplier($supplier);
-       if ($supplier != null)
+       if ($supplier != null) {
                $currency = $supp['curr_code'];
-       else
+        if ($supp['tax_included'])
+            $price = get_tax_free_price_for_item($stock_id, $price, $supp['tax_group_id'],
+                $supp['tax_included']);
+    } else
                $currency = null;
 
-       if ($supp['tax_included'])
-               $price = get_tax_free_price_for_item($stock_id, $price, $supp['tax_group_id'],
-                       $supp['tax_included']);
-
        if ($currency != null)
        {
                $ex_rate = get_exchange_rate_to_home_currency($currency, $date);

Re: PHP 7.4 bug

Thanks. Committed to 2.4.8 repo.

Joe

Re: PHP 7.4 bug

Trying to install FA 2.4.8 with PHP 7.4.3 on Linux Mint 20 to go from FA 2.4.4 on Linux Mint 19. When installing I get the following error:
Trying to access array offset on value of type null in file: /var/www/html/frontaccounting/install/isession.inc at line 140
If I ignore the error, the install goes on but returns an error:
Trying to access array offset on value of type null in file: /var/www/html/frontaccounting/includes/db/connect_db_mysqli.inc at line 55
Apparently it is starts OK with an US 4 digit COA and Spanish interface. I can then upload a back-up from our working system (after increasing the parameters in the php.ini file), but it will not restore from the backup file (11 MB gzip file). I have tried doing the restore in phpmyadmin, but it turns up a blank page.
Any hint?

Re: PHP 7.4 bug

The isession.inc error is because you have not installed the locale (Spanish and en_US in your case) in your Linux Mint. FA generally degrades to 'C' language only if you did not choose a valid (and possibly not installed) language.

Use mysql restore from backup sql file from the CLI.

Re: PHP 7.4 bug

Thanks for the clarification. I suspected it was a language issue.

When starting the FA installation there are actually a lot of warnings, which disappear when i try login once again:
* include_once(../installed_extensions.php): failed to open stream: No such file or directory in file: /var/www/html/frontaccounting/frontaccounting.php at line 23
* include_once(): Failed opening '../installed_extensions.php' for inclusion (include_path='.:/usr/share/php') in file: /var/www/html/frontaccounting/frontaccounting.php at line 23
* include_once(../config_db.php): failed to open stream: No such file or directory in file: /var/www/html/frontaccounting/includes/session.inc at line 383
* include_once(): Failed opening '../config_db.php' for inclusion (include_path='.:/usr/share/php') in file: /var/www/html/frontaccounting/includes/session.inc at line 383
* Undefined variable: installed_extensions in file: /var/www/html/frontaccounting/includes/session.inc at line 392
Line 383 in sessions.inc is:
"include_once($path_to_root . "/config_db.php");"
Line 392 in sessions.inc is:
"foreach ($installed_extensions as $ext)"

Regarding the language this has been a pain in each new installation since we started using FA 8 years ago. I have managed to get it to work, but I am a bit lost in the question of utf8 vs. ISO. Which of those am I supposed to install? According to phpmyadmin utf8_unicode_ci is the default for creating databases and my FA db is utf8.

Re: PHP 7.4 bug

After overriding the initial errors, I now get:
Trying to access array offset on value of type null in file: /var/www/html/frontaccounting/includes/db/connect_db_mysqli.inc at line 55
Line 55 is:
    $cur_prefix = $db_connections[$comp]['tbpref'];

Re: PHP 7.4 bug

I used the Mysql restore. First problems with the timestamp (ERROR 1067). After adding
mysql> SET @@session.sql_mode =" ";
the restore worked. Thanks.

Re: PHP 7.4 bug

We have another issue {$} in reporting\includes\Workbook.php.

@joe. kindly update them to work on php 8.0

Subscription service based on FA
HRM CRM POS batch Themes

Re: PHP 7.4 bug

@kvvaradha

Workbook.php has been fixed and committed to stable. A fixed file /reporting/includes/workbook.php can be downloaded and replaced here.

Joe