Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PHP 8.0
10-09-2020, 10:48 PM,
#1
PHP 8.0
I have mentioned this to a few developers privately, but time is running out and a plan needs to be made.

In a little over a month on the 23rd November PHP 8.0 will be released. This release follows the recent trend of PHP releases and turns several more Notices/Warnings into fatal errors. This breaks some core functionality of webERP.

For instance I noticed when looking at the GetPrice.php script for another thread, that while creating a sales order, searching for stock items throws the following:

Notice: Undefined variable: j in webERP-svn/SelectOrderItems.php on line 1768
Notice: Undefined variable: j in webERP-svn/SelectOrderItems.php on line 1769
Notice: Undefined variable: j in webERP-svn/SelectOrderItems.php on line 1772


Under PHP 8 this would cause the script to throw a fatal error and stop working. Unfortunately I know of no easy way to search for these issues, other than setting error_reporting() to -1 and adding the line ini_set('display_errors', 1); in config.php, and then working through all the functionality then noting down any Notices or Warnings issued. This is a lengthy job, but unless someone knows a better way it needs doing.

This "Undefined variable" issue is just one of quite a few breaking changes in PHP 8, it is just one that I happened to notice.

Tim

NB I have said for many years that except in production environments developers should always have error_reporting set to -1 and display_errors set to 1.
Reply
10-11-2020, 03:05 AM, (This post was last modified: 10-11-2020, 04:33 AM by TurboPT.)
#2
RE: PHP 8.0
I crossed a tool called PHPStan  (Stan = Static Analysis)

However, it's been a little tough previewing so far, as it's optimized for OO code, rather than the procedural/OO mix of things as we have. Stan can scan directories of php files as well (as their examples show covering a src/ and test/ directories), but we have many files at our root level that are not, so those may have to be scripted to ease the checking. (I've been wanting to clean up our root, a lower priority at the moment though)

Doesn't appear to automatically pull other definitions (like from the include files), but getting a basic config which specifies some include files to read at startup, and running a check on the same file gave the output below:

(Obviously, I do not yet have many other related definitions covered, such as the property object:: stuff, and others.)
At first, there were ~140 errors before getting other definitions covered.

Code:
  Line   SelectOrderItems.php
------ ---------------------------------------------------------------
  57     Variable $NewItemArray might not be defined.
  60     Variable $InsertNum might not be defined.
  60     Variable $Row might not be defined.
  84     Class Cart referenced with incorrect case: cart.
  86     Variable $CustomerLogin might not be defined.
  111    Class Cart referenced with incorrect case: cart.
  178    Variable $CustomerLogin might not be defined.
  309    Variable $LastLineNo might not be defined.
  322    Class Cart referenced with incorrect case: cart.
  417    Variable $SelectedBranch might not be defined.
  468    Variable $debug might not be defined.
  593    Variable $RootPath might not be defined.
  593    Variable $Theme might not be defined.
  700    Class Cart referenced with incorrect case: cart.
  714    Variable $RootPath might not be defined.
  714    Variable $Theme might not be defined.
  716    Access to an undefined property object::$Quotation.
  722    Access to an undefined property object::$CustomerName.
  723    Access to an undefined property object::$DeliverTo.
  724    Access to an undefined property object::$LocationName.
  725    Access to an undefined property object::$SalesTypeName.
  726    Access to an undefined property object::$PaymentTerms.
  838    Access to an undefined property object::$DefaultCurrency.
  839    Access to an undefined property object::$DefaultCurrency.
  880    Access to an undefined property object::$DeliveryDays.
  896    Access to an undefined property object::$DeliveryDays.
  922    Variable $NewItemQty might not be defined.
  1036   Call to an undefined method object::Some_Already_Delivered().
  1038   Call to an undefined method object::remove_from_cart().
  1040   Access to an undefined property object::$LineItems.
  1046   Access to an undefined property object::$LineItems.
  1098   Variable $ItemDue might not be defined.
  1098   Variable $NewItem might not be defined.
  1100   Access to an undefined property object::$DeliveryDays.
  1104   Access to an undefined property object::$LineItems.
  1104   Call to an undefined method object::Some_Already_Delivered().
  1106   Access to an undefined property object::$LineItems.
  1106   Call to an undefined method object::Some_Already_Delivered().
  1110   Access to an undefined property object::$LineItems.
  1124   Access to an undefined property object::$CreditAvailable.
  1138   Call to an undefined method object::update_cart_item().
  1156   Access to an undefined property object::$LineItems.
  1162   Access to an undefined property object::$LineItems.
  1170   Access to an undefined property object::$DefaultSalesType.
  1180   Access to an undefined property object::$LineItems.
  1182   Access to an undefined property object::$LineItems.
  1183   Access to an undefined property object::$LineItems.
  1183   Access to an undefined property object::$LineItems.
  1183   Access to an undefined property object::$LineItems.
  1183   Access to an undefined property object::$LineItems.
  1191   Variable $RootPath might not be defined.
  1193   Variable $RootPath might not be defined.
  1295   Access to an undefined property object::$LineItems.
  1301   Access to an undefined property object::$LineItems.
  1309   Access to an undefined property object::$DefaultSalesType.
  1319   Access to an undefined property object::$LineItems.
  1321   Access to an undefined property object::$LineItems.
  1328   Access to an undefined property object::$LineItems.
  1332   Access to an undefined property object::$DefaultPOLine.
  1368   Access to an undefined property object::$total.
  1369   Access to an undefined property object::$totalVolume.
  1370   Access to an undefined property object::$totalWeight.
  1372   Access to an undefined property object::$LineItems.
  1375   Access to an undefined property object::$CurrDecimalPlaces.
  1396   Variable $RootPath might not be defined.
  1410   Access to an undefined property object::$CurrDecimalPlaces.
  1414   Access to an undefined property object::$CurrDecimalPlaces.
  1415   Access to an undefined property object::$CurrDecimalPlaces.
  1420   Call to an undefined method object::Some_Already_Delivered().
  1428   Access to an undefined property object::$DeliveryDays.
  1429   Access to an undefined property object::$LineItems.
  1453   Access to an undefined property object::$CurrDecimalPlaces.
  1510   Variable $RootPath might not be defined.
  1510   Variable $Theme might not be defined.
  1541   Access to an undefined property object::$Location.
  1550   Access to an undefined property object::$Location.
  1555   Access to an undefined property object::$Location.
  1609   Variable $RootPath might not be defined.
  1609   Variable $Theme might not be defined.
  1686   Variable $Offset might not be defined.
  1688   Variable $Offset might not be defined.
  1714   Access to an undefined property object::$Location.
  1723   Access to an undefined property object::$Location.
  1728   Access to an undefined property object::$Location.
  1768   Variable $j might not be defined.
  1769   Variable $j might not be defined.
  1772   Variable $j might not be defined.
  1779   Variable $Offset might not be defined.
  1781   Variable $Offset might not be defined.
  1794   Access to an undefined property object::$DefaultPOLine.
  1801   Access to an undefined property object::$DeliveryDays.
  1806   Access to an undefined property object::$DefaultPOLine.
  1827   Access to an undefined property object::$DefaultPOLine.
  1867   Access to an undefined property object::$ItemsOrdered.
------ ---------------------------------------------------------------

[ERROR] Found 94 errors

I'll tinker with stan a little more over the weekend to see if it could possibly be useful, or it could turn out to be more trouble than it's worth and need seek some other resource. There are other configurable items with this tool, maybe I could check only for the might not be defined things first.
Reply
10-11-2020, 07:35 AM,
#3
RE: PHP 8.0
Thanks Paul, that looks interesting. I will have a look at it myself.

At first sight it seems to give a lot of false positives, but that may be because SelectOrderItems.php is one of the longer and more complex scripts we have.

Tim
Reply
10-11-2020, 11:29 PM, (This post was last modified: 10-11-2020, 11:43 PM by TurboPT.)
#4
RE: PHP 8.0
Yeah, quite a few false positives, but again it doesn't seem to automatically reference the includes already within the file to resolve definitions, unless I'm misunderstanding some of its use.

I created this config file (I named stan.neon, placed in webERP root directory) to add some definition references: (which reduced errors not shown in yesterdays run from ~140 down to the 94)

Code:
parameters:
    level: 4
    scanFiles:
      - includes/ConnectDB_mysqli.inc
      - includes/DefinePOClass.php
      - includes/DateFunctions.inc
      - includes/SQL_CommonFunctions.inc
      - includes/session.php
    scanDirectories:
      - includes

Then used that with the command line:

Quote:>vendor\bin\phpstan analyse -c stan.neon SelectOrderItems.php

I'm still new with the tool, though, so I may be missing some aspects.
Reply
10-12-2020, 01:39 AM, (This post was last modified: 10-12-2020, 01:39 AM by TurboPT.)
#5
RE: PHP 8.0
Here's an updated stan.neon config, checks the entire includes/ dir, without running out of memory, ignoring the 3rd party dirs (phplot, tcpdf, etc) ... still many false positives, but still working through the configuration:

Code:
parameters:
    level: 5
    scanFiles:
      - includes/DefinePOClass.php
      - includes/DefineCartClass.php
      - includes/DefinePOClass.php
      - includes/ConnectDB_mysqli.inc
      - includes/SQL_CommonFunctions.inc
      - includes/class.pdf.php
    scanDirectories:
      - includes
    paths:
      - includes
    fileExtensions:
      - php
      - inc
    excludes_analyse:
      - includes/phplot
      - includes/tcpdf
      - includes/php-gettext
      - includes/barcodepack

Run with command: (note, no file at the end as was previously done, the paths: option in the config specifies where to scan)

Quote:>vendor\bin\phpstan analyse -c stan.neon
Reply
10-12-2020, 07:10 AM,
#6
RE: PHP 8.0
Thanks for that Paul, I will look tomorrow and provide feedback.

Tim
Reply
10-13-2020, 11:14 AM, (This post was last modified: 10-13-2020, 11:15 AM by TurboPT.)
#7
RE: PHP 8.0
Here's my last config. Weird that even adding extra files that some definitions that I expected to resolve did not?
Code:
parameters:
    level: 5
    bootstrapFiles:
      - config.php
    scanFiles:
      - includes/class.pdf.php
      - includes/ConnectDB.inc
      - includes/ConnectDB_mysqli.inc
      - includes/InputSerialItems.php
      - includes/DateFunctions.inc
      - includes/DefineCartClass.php
      - includes/DefinePOClass.php
      - includes/GetConfig.php
      - includes/LanguageSetup.php
      - includes/SQL_CommonFunctions.inc
    scanDirectories:
      - includes
    paths:
      - includes
    fileExtensions:
      - php
      - inc
    excludes_analyse:
      - includes/phplot
      - includes/tcpdf
      - includes/php-gettext
      - includes/barcodepack

Anyway, I've not yet given up 100%, but I might start considering other tools, unless you've had more success than me?

There is a long list of related tools available for PHP.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)