Menu

#2961 PHP 8.1.1 deprecations - Take 6

v4.3.1
closed-fixed
None
5
2022-01-23
2022-01-18
No

Gerry,
below is a list of some missing globals and minor spelling corrections. Only one correction concerns 8.1.1 (concatenate to null string). 'a' states for main project directory.

BTW:
the SQL query from the previous part works OK now. The old version didn't work also in Microsoft MSSQL, not only in postgreSQL. In these DBs SELECT DISTINCT, if uses ORDER BY or GROUP BY, must have columns expressed explicitly. Without DISTINCT, it is needn't.

--- a/blocks/cookiepolicy.php (revision 7329)
line 35: add
global $pgv_lang;

--- a/includes/classes/class_reportbase.php (revision 7329)
line 254: correct aproximate -> approximate
line 256: correct Stationery -> Stationary
line 715: correct caracter -> character

--- a/modules/googlemap/admin-config.php (revision 7329)
line 36: add
global $pgv_lang;

--- a/modules/googlemap/editconfig_help.php (revision 7329)
line 33: add
global $pgv_lang;

--- a/modules/lightbox/languages/lang.da.php (revision 7329)
--- a/modules/lightbox/languages/lang.de.php (revision 7329)
--- a/modules/lightbox/languages/lang.en.php (revision 7329)
--- a/modules/lightbox/languages/lang.es.php (revision 7329)
--- a/modules/lightbox/languages/lang.fi.php (revision 7329)
--- a/modules/lightbox/languages/lang.fr.php (revision 7329)
--- a/modules/lightbox/languages/lang.he.php (revision 7329)
--- a/modules/lightbox/languages/lang.no.php (revision 7329)
--- a/modules/lightbox/languages/lang.pl.php (revision 7329)
--- a/modules/lightbox/languages/lang.sl.php (revision 7329)
--- a/modules/lightbox/languages/lang.tr.php (revision 7329)
in all these files: line 35: add
global $factarray

--- a/modules/lightbox/admin-config.php (revision 7329)
line 36: add
global $pgv_lang;

--- a/modules/lightbox/lb_editconfig_help.php (revision 7329)
line 33: add
global $pgv_lang;

--- a/modules/research_assistant/editcomment.php (revision 7329)
line 29: add
global $pgv_lang;

--- a/modules/research_assistant/research_assistant.php (revision 7329)
line 513: change .= to = (at this moment $out is null/unset/whatever - terrible for php 8.1)

--- a/edit_interface.php (revision 7329)
line 2249: change array -> Array

--- a/searchhelp.php (revision 7329)
line 145: add
global $pgv_lang; // must be redeclared after being unset 3 lines up

Discussion

  • Tomasz Babczyński

    This Stationery was correct, sorry, checked without context.

     
  • Gerry Kroll

    Gerry Kroll - 2022-01-18

    Tomasz:
    I disagree about the need to add those global $pgv_lang and $global $factarray etc.

    These are defined at the global level in function loadLangFile, and are thus visible outside the function as well.

    The attached test script demonstrates this. It works under PHP 5.3.10 as well as PHP 7.4.27 . I don't believe this has changed in PHP 8, although I could be wrong here.

     
    • Tomasz Babczyński

      Gerry,
      yes, you are right, it works also in PHP 8.0.10. But it seems unpleasant to me a bit. All variables initialized in global scope (no, not declared as global but simply used outside any function) are global. So, what's the point of using global outside of functions? Maybe I'm wrong but I treated this keyword like extern in C - "the variable is defined in another file (not included) but I want to use it also here".
      The point is also that I like to see declarations (at least as a kind of includes). Maybe it's redundancy, but if the definition of a variable is inside a function, I don't know that it has been declared at all. The compiler or interpreter does, of course.

       
  • Gerry Kroll

    Gerry Kroll - 2022-01-18

    Variables at nesting level zero are always global in scope, and don't need to be declared as such.

    Nesting level zero is the main program and any other scripts that are loaded by means of REQUIRE or INCLUDE.

    If the script being loaded by means of REQUIRE or INCLUDE contains functions, the variables used or declared inside those functions are local to the function, unless they are mentioned in a GLOBAL statement inside that function. This means that functions are always re-entrant.

     
    • Tomasz Babczyński

      Yes, Gerry, you're right. Formally it is all correct. But I will still dislike situations where globals are declared in functions. The present script, the REQUIRE and INCLUDE are the "natural" places where we can find declarations. If they are hidden in functions, I feel a smell. Of course, variables can be filled in inside functions even without parameters or return values but for declarations (in PHP, actually first assignment), I feel uncomfortable. Usually there is a bunch of functions called but only a few INCLUDEs or REQUIREs and finding variables there is easier.

       
      • Gerry Kroll

        Gerry Kroll - 2022-01-20

        Tomasz:
        I understand where you're coming from. However, in PhpGedView, adding those explicit GLOBAL declarations where they're not necessary adds needless complications and doesn't really make the program any easier to understand.

        If you insist on explicitly declaring EVERY automatic GLOBAL, you're going to run into a real mess where it comes to the declarations within the various configuration files. The GEDCOM configuration file, for example, contains over a hundred declarations. Surely you don't want to list every one of these in a GLOBAL statement?

         
  • Gerry Kroll

    Gerry Kroll - 2022-01-18
    • assigned_to: Gerry Kroll
     
  • Gerry Kroll

    Gerry Kroll - 2022-01-19

    The latest iteration of updates to PhpGedView is attached. It contains a few bug fixes and also some corrections to comments in class_reportbase.php.

     

    Last edit: Gerry Kroll 2022-01-23
  • Gerry Kroll

    Gerry Kroll - 2022-01-23
    • status: open --> closed-fixed
     
  • Gerry Kroll

    Gerry Kroll - 2022-01-23

    SVN 7331 contains the latest set of fixes. They are also in the attachment FixPGV6.zip .

    New "observations" or "undocumented features" should be reported in a new post.

     

Log in to post a comment.