Menu

#3783 PHP 5.2 incompabilities

4.0.0
fixed
None
5
2013-06-11
2013-01-24
JT Graveaud
No

Hi,
looks like the latest release has some code typo:
When you select a database (on the left menu) and see the whole list of tables, click on the "Structure" link of one of the tables and I get this error message (in php_error.log)
[24-Jan-2013 07:43:01] PHP Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM in /web/xuropa.com/public/phpm/phpm/libraries/DisplayResults.class.php on line 5412
[24-Jan-2013 07:43:01] PHP Stack trace:
[24-Jan-2013 07:43:01] PHP 1. {main}() /web/xuropa.com/public/phpm/phpm/sql.php:0

This error appears because an incorrect syntax:
$transformation_plugin::getMIMESubtype()
which I replaced by
$transformation_plugin->getMIMESubtype()

look for the 3 or 4 other similar call issues by the following command at the root path:

find . -name "*.php" -exec egrep -n "\\$[0-9a-zA-Z_]*::" {} \; -print

Note: there are 3 anti slashes in the in the bash command above (but only 2 appear after submitting this ticket)

Thanks
JT

Related

Bugs: #3792
Bugs: #3876

Discussion

  • Marc Delisle

    Marc Delisle - 2013-01-24

    Hi,
    which PHP version are you using? From Documentation.html, "You need PHP 5.2.0 or newer, with session support, the Standard PHP Library (SPL) extension and JSON support."

     
  • Marc Delisle

    Marc Delisle - 2013-01-24
    • assigned_to: Marc Delisle
     
  • JT Graveaud

    JT Graveaud - 2013-01-24

    Hi Marc,
    I'm using PHP 5.2.8
    Regards.
    JT

     

    Last edit: JT Graveaud 2013-01-25
  • Marc Delisle

    Marc Delisle - 2013-01-25

    I cannot reproduce this problem (but I'm testing in PHP 5.4). Does it happen for all your databases? Are you using phpMyAdmin 4.0.0-alpha1?

     

    Last edit: Marc Delisle 2013-01-25
  • JT Graveaud

    JT Graveaud - 2013-01-25

    Marc,
    Yes, this happens for all databases. I'm using 4.0.0-alpha1

    Your issue comes from a subtlety that has changed in PHP 5.3
    http://php.net/manual/en/language.oop5.static.php

    I've just tested the following code with PHP Version 5.3.2 (in the same condition as you do), this does not generate any error.

    class A {
    static function myfunct() { return "Plain"; }
    }
    $A = new A();
    print $A::myfunct();

    However it does generate the following error on PHP Version 5.2.8.

    [25-Jan-2013 10:00:22] PHP Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM in /web/public/test.php on line 6

    So, as I mentionned in my first post, you can replace the :: by -> (if you want to keep the minimal version of PMA as PHP 5.2)

    I've found less than 10 occurrences in the whole code, which is acceptable I think to replace in order to keep PHP 5.2 as minimal.

    JT

     
  • Marc Delisle

    Marc Delisle - 2013-01-25

    Thanks for the explanation. I'll make the changes, but how do you make your search, to find these 10 occurences?

     
  • JT Graveaud

    JT Graveaud - 2013-01-25

    You're welcome Marc ;-)

    here is the command I used to find out:

    find . -name "*.php" -exec egrep -n "\\$[0-9a-zA-Z_]*::" {} \; -print

    This command searches all PHP variables (ie, string starting by $) and followed by ::

    as noted in my original email, please not there are 3 backslashes in front of the dollar sign (the sourceforge Form analyzer strips one backslash out when I submit the post.

    To be accurate, there are 6 variables to fix to be accurate:

    338: . $this::texEscape(stripslashes($columns[$i])) . '}} & ';
    381: $column_value = $this::texEscape(
    613: $local_buffer = $this::texEscape($local_buffer);
    ./libraries/plugins/export/ExportLatex.class.php

    3873: && ! strpos($transformation_plugin::getName(), 'Link') === true
    5412: && strpos($transformation_plugin::getMIMESubtype(), 'Octetstream')
    ./libraries/DisplayResults.class.php

    150: return $class_name::getInfo();
    ./libraries/transformations.lib.php

    Regards.

    JT

     
  • Dieter Adriaenssens

    the $this::texEscape should become self::texEscape
    or
    texEscape should be made nonstatic and :: replaced by ->

    the transformation_plugins should work with replacing :: by ->

     

    Last edit: Dieter Adriaenssens 2013-01-25
  • Dieter Adriaenssens

    Basically, it is never a good idea to mix :: (which is associated with calling static methods from a non instanciated class) with instances, or -> (which is for accessing methods and properties for class instances) with a non-instanciated class. (even if PHP allows it from 5.3)

    In case of the $transformation_plugins it is hard to do it correct, unless that part is refactored.

     
  • Dieter Adriaenssens

    fixed (texEscape) in
    commit 688642560d0c07d46cb7121e759eccda7cabbb70 (https://github.com/phpmyadmin/phpmyadmin/commit/688642560d0c07d46cb7121e759eccda7cabbb70)

    and ($transformation_plugins) in
    commit d53f984a71225700036bcb6108e01ae60dc0c456 (https://github.com/phpmyadmin/phpmyadmin/commit/d53f984a71225700036bcb6108e01ae60dc0c456)

    JT : could you pull latest git, or apply these commits to your setup and test with PHP 5.2.*?

    BTW :

    150: return $class_name::getInfo();
    ./libraries/transformations.lib.php
    is correct, because $class_name contains the name of a class, not an instance

     
  • Dieter Adriaenssens

    • status: open --> pending-fixed
    • assigned_to: Marc Delisle --> Dieter Adriaenssens
     
  • Marc Delisle

    Marc Delisle - 2013-01-26

    @JT: thanks, I had missed the search command in your initial post

    @Dieter: I installed PHP 5.2. With
    150: return $class_name::getInfo();
    I cannot list a table's structure, so I fixed this with https://github.com/phpmyadmin/phpmyadmin/commit/4e565265f7bde71854b64afa97b967d57be7b5c6

     

    Last edit: Marc Delisle 2013-01-27
  • Marc Delisle

    Marc Delisle - 2013-01-26
    • summary: Syntax error in some modules : unexpected T_PAAMAYIM_NEKUDOTAYIM --> PHP 5.2 incompabilities
     
  • JT Graveaud

    JT Graveaud - 2013-01-27

    We're all good ;-) the modifications suggested (in the 3 files you both already committed) fixed the issue on my side. Perfect !

    Thanks guys.
    JT

     
  • Marc Delisle

    Marc Delisle - 2013-01-27

    JT,
    thanks for confirming, but there is a doubt about one of the commits, see https://sourceforge.net/p/phpmyadmin/bugs/3792/. The demo server runs PHP 5.4.4 + fastcgi.

     
  • JT Graveaud

    JT Graveaud - 2013-01-27

    Marc, I've just done more specific tests, and I confirm there is a mutual conflict between the 2 tickets (ticket 3792 and the fix for ticket 3783).

    I get the error (in my personal test when I use '->' on a static method):
    Fatal error: Call to a member function myfunct2() on a non-object

    I'm going to have a look on how to solve this issue on both PHP release 5.2.8 & 5.3 I have and if I find something before you do, I'll let you know of course.
    JT

     
  • JT Graveaud

    JT Graveaud - 2013-01-27

    Marc, Dieter,
    Looks like if you decide to keep 5.2 as minimal PHP release, the main & quick (but really not clean) option is

    switch ($class_name) {
    case 'Application_Octetstream_Download': $ret=Application_Octetstream_Download::getInfo(); break;
    case 'Application_Octetstream_Hex': $ret=Application_Octetstream_Hex::getInfo(); break;
    case 'Image_JPEG_Inline': $ret=Image_JPEG_Inline::getInfo(); break;
    case 'Image_JPEG_Link': $ret=Image_JPEG_Link::getInfo(); break;
    case 'Image_PNG_Inline': $ret=Image_PNG_Inline::getInfo(); break;
    case 'Text_Plain_Append': $ret=Text_Plain_Append::getInfo(); break;
    case 'Text_Plain_Dateformat': $ret=Text_Plain_Dateformat::getInfo(); break;
    case 'Text_Plain_External': $ret=Text_Plain_External::getInfo(); break;
    case 'Text_Plain_Formatted': $ret=Text_Plain_Formatted::getInfo(); break;
    case 'Text_Plain_Imagelink': $ret=Text_Plain_Imagelink::getInfo(); break;
    case 'Text_Plain_Link': $ret=Text_Plain_Link::getInfo(); break;
    case 'Text_Plain_Longtoipv4': $ret=Text_Plain_Longtoipv4::getInfo(); break;
    case 'Text_Plain_Sql': $ret=Text_Plain_Sql::getInfo(); break;
    case 'Text_Plain_Substring': $ret=Text_Plain_Substring::getInfo(); break;
    }
    return $ret;

    A more generic option (but still not clean at all option) would be to make this piece of "switch" code into a cached file, and therefore do something like:

    if (!file_exists("CallStatic_getInfo.php")) {
    // create here dynamically the switch block suggested above in CallStatic_getInfo.php
    // based on files listed in libraries/plugins/transformations/*.class.php
    }

    include "CallStatic_getInfo.php";
    return $ret;

    unfortunately none of those 2 options are nice but they keep 5.2 in the loop, otherwise PHP 5.3 is your minimum. Hopefully somebody else will have a better idea.

    Cheers

    JT

    PS: Note: I've tested all sort of other options (such as eval, etc), but none have been succefful with Both release (5.2.8 & 5.3)

     

    Last edit: JT Graveaud 2013-01-27
  • Dieter Adriaenssens

    This patch should fix it (pull request : https://github.com/phpmyadmin/phpmyadmin/pull/146)

    It works in PHP 5.3.x and should as well in PHP 5.2.x
    Can you test, Marc, Michal, JT?

     

    Last edit: Dieter Adriaenssens 2013-01-27
  • JT Graveaud

    JT Graveaud - 2013-01-27

    perfect, much better solution.
    The following code works for me on both platform

    // include and instantiate the class
    include_once 'libraries/plugins/transformations/' . $file;
    $class = new $class_name;
    return $class->getInfo();
    

    Thanks.
    JT

     
  • Marc Delisle

    Marc Delisle - 2013-01-27

    Dieter's patch merged, thanks.

     
  • Marc Delisle

    Marc Delisle - 2013-02-10
    • status: pending-fixed --> closed-fixed
     
  • NewEraCracker

    NewEraCracker - 2013-04-13

    with 4.0.0-rc1

    Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM, expecting ',' or ';' in C:\server\www\phpMyAdmin\libraries\display_import.lib.php on line 171

    the line is:
    echo $_SESSION[$SESSION_KEY]["handler"]::getIdKey();

    Reported here:
    https://sourceforge.net/p/phpmyadmin/bugs/3876/

     

    Last edit: NewEraCracker 2013-04-13
  • Michal Čihař

    Michal Čihař - 2013-06-11
    • Status: closed-fixed --> fixed