sql-parser icon indicating copy to clipboard operation
sql-parser copied to clipboard

NOTICE: PHP message: PHP Fatal error: Uncaught TypeError: implode() expects parameter 2 to be array, null given in src/Utils/Routine.php:123

Open williamdes opened this issue 5 years ago • 2 comments

NOTICE: PHP message: PHP Fatal error:  Uncaught TypeError: implode() expects parameter 2 to be array, null given in vendor/phpmyadmin/sql-parser/src/Utils/Routine.php:123"
Stack trace:"
#0 vendor/phpmyadmin/sql-parser/src/Utils/Routine.php(123): implode(',', NULL)"
#1 libraries/classes/Rte/RteList.php(304): PhpMyAdmin\SqlParser\Utils\Routine::getParameters(Object(PhpMyAdmin\SqlParser\Statements\CreateStatement))"
#2 libraries/classes/Rte/RteList.php(169): PhpMyAdmin\Rte\RteList->getRoutineRow(Array, '')"
#3 libraries/classes/Rte/Routines.php(131): PhpMyAdmin\Rte\RteList->get('routine', Array)"
#4 libraries/classes/Controllers/Database/RoutinesController.php(42): PhpMyAdmin\Rte\Routines->main('PROCEDURE')"
#5 db_routi..."

williamdes avatar Feb 28 '20 22:02 williamdes

{
    "name": {
        "database": null,
        "table": "foo",
        "column": null,
        "expr": "`foo`",
        "alias": null,
        "function": null,
        "subquery": null
    },
    "entityOptions": {
        "options": []
    },
    "fields": null,
    "select": null,
    "like": null,
    "partitionBy": null,
    "partitionsNum": null,
    "subpartitionBy": null,
    "subpartitionsNum": null,
    "partitions": null,
    "table": null,
    "return": null,
    "parameters": [
        {
            "name": "$",
            "inOut": null,
            "type": {
                "name": "FOO",
                "parameters": [],
                "options": {
                    "options": []
                }
            }
        },
        {
            "name": null,
            "inOut": null,
            "type": null
        }
    ],
    "body": [
        {
            "token": "select",
            "value": "SELECT",
            "keyword": "SELECT",
            "type": 1,
            "flags": 3,
            "position": 54
        },
        {
            "token": " ",
            "value": " ",
            "keyword": null,
            "type": 3,
            "flags": 0,
            "position": 60
        },
        {
            "token": "$",
            "value": "$",
            "keyword": null,
            "type": 0,
            "flags": 0,
            "position": 61
        },
        {
            "token": "foo",
            "value": "foo",
            "keyword": null,
            "type": 0,
            "flags": 0,
            "position": 62
        },
        {
            "token": null,
            "value": null,
            "keyword": null,
            "type": 9,
            "flags": 0,
            "position": null
        }
    ],
    "options": {
        "options": {
            "4": {
                "name": "DEFINER",
                "equals": true,
                "expr": {
                    "database": null,
                    "table": null,
                    "column": "root@%",
                    "expr": "`root`@`%`",
                    "alias": null,
                    "function": null,
                    "subquery": null
                },
                "value": "`root`@`%`"
            },
            "6": "PROCEDURE"
        }
    },
    "first": 0,
    "last": 23
}

passed to getParameters

williamdes avatar Feb 28 '20 22:02 williamdes

CREATE DEFINER=`root`@`%` PROCEDURE `$a`(IN `$a` INT)
    NO SQL
SELECT $a
-- or
CREATE DEFINER=`root`@`%` PROCEDURE `foo`( $foo int )
select $foo

I had no success adding a test


    public function testGetParametersFromCreateStatement()
    {
        //CREATE DEFINER=`root`@`%` PROCEDURE `$a`(IN `$a` INT)\n    NO SQL\nSELECT $a
        $parser = new Parser('CREATE DEFINER=`root`@`%` PROCEDURE `foo`( $foo int )\nselect $foo');

        /**
         * @var CreateStatement $stmt
         */
        $stmt = $parser->statements[0];

        $this->assertNotNull(Routine::getParameters($stmt));
    }

williamdes avatar Feb 28 '20 23:02 williamdes

@williamdes using the current master, I can't reproduced, and I experience 0 PHP error by linting your queries. Is this still something you can reproduce? Otherwise, I think you can close this one as it's probably no longer a bug.

niconoe- avatar Feb 28 '23 13:02 niconoe-

@williamdes using the current master, I can't reproduced, and I experience 0 PHP error by linting your queries. Is this still something you can reproduce? Otherwise, I think you can close this one as it's probably no longer a bug.

Thank you for trying this, please be sure to try on QA_5_2 branch as it's the maintenance branch That said I did a fix years ago to the line that did trigger this so it would shut up. but it's only a workaround I put this back to un-read and will try to find you the commit ASAP

williamdes avatar Feb 28 '23 22:02 williamdes

Well, I can not find it anymore. Searched everywhere, it's lost or gone for ever. We should probably add a test case for the code I sent because parameters are wrongly detected

The only one I found was way back before this issue 🤔 https://github.com/phpmyadmin/phpmyadmin/pull/14750

So maybe re-creating the bug would help finding my workaround. But that's not worth the research time

williamdes avatar Mar 09 '23 22:03 williamdes

Well, I guess your workaround evolved to something better then 😄 Maybe this issue should be closed if it doesn't happen anymore.

niconoe- avatar Mar 09 '23 23:03 niconoe-

Well, I guess your workaround evolved to something better then smile Maybe this issue should be closed if it doesn't happen anymore.

Yeah probably 😄 But I can not close it because as I said parameters in https://github.com/phpmyadmin/sql-parser/issues/293#issuecomment-592764284 are wrong ;p

williamdes avatar Mar 09 '23 23:03 williamdes

Sorry, I didn't noticed that parameters were wrong 😅 I guess for

CREATE DEFINER=`root`@`%` PROCEDURE `foo`( $foo int )

you expect something like:

"parameters":[
  {
    "name": "$foo",
    "inOut": null,
    "type": "int"
  }
]

right?

niconoe- avatar Mar 09 '23 23:03 niconoe-

Exactly, and I am not sure if it should also do one token for

{
            "token": "$",
            "value": "$",
            "keyword": null,
            "type": 0,
            "flags": 0,
            "position": 61
        },
        {
            "token": "foo",
            "value": "foo",
            "keyword": null,
            "type": 0,
            "flags": 0,
            "position": 62
        },

Instead of two

williamdes avatar Mar 09 '23 23:03 williamdes

FTR I think this was https://github.com/phpmyadmin/phpmyadmin/issues/15991

williamdes avatar Mar 09 '23 23:03 williamdes

Thanks a lot! I'll try to take a look, probably next week.

niconoe- avatar Mar 10 '23 00:03 niconoe-

Parameter name seems to be correct now, isn't it? image

Tithugues avatar Apr 12 '23 12:04 Tithugues

Yes, let's close this one. I am not sure where it was anyway. Should have posted a reference back in the day. Thanks for having a look too

williamdes avatar Apr 14 '23 11:04 williamdes