Php 8.2 compatibility: Passing null to parameter #1 ($string) of type string is deprecated

Wappler Version : 6.8
Operating System : Win11
Server Model: PHP (8.2)
Database Type: MySQL
Hosting Type: --

Expected vs actual behavior

My hosting provider upgraded PHP to 8.2 and I saw deprecated error after the fact:

{
    "code": 0,
    "file": "\/home\/customer\/www\/circles.icu\/public_html\/dmxConnectLib\/lib\/formatters\/crypto.php",
    "line": 56,
    "message": "strlen(): Passing null to parameter #1 ($string) of type string is deprecated",
    "trace": "#0 [internal function]: exception_error_handler(8192, 'strlen(): Passi...', '\/home\/customer\/...', 56)\n#1 \/home\/customer\/www\/circles.icu\/public_html\/dmxConnectLib\/lib\/formatters\/crypto.php(56): strlen(NULL)\n#2 [internal function]: lib\\core\\formatter_encrypt(NULL, 'circles')\n#3 \/home\/customer\/www\/circles.icu\/public_html\/dmxConnectLib\/lib\/core\/Parser.php(419): call_user_func_array('\\\\lib\\\\core\\\\forma...', Array)\n#4 \/home\/customer\/www\/circles.icu\/public_html\/dmxConnectLib\/lib\/core\/Parser.php(372): lib\\core\\Parser->objectMember(Object(Closure))\n#5 \/home\/customer\/www\/circles.icu\/public_html\/dmxConnectLib\/lib\/core\/Parser.php(314): lib\\core\\Parser->primary()\n#6 \/home\/customer\/www\/circles.icu\/public_html\/dmxConnectLib\/lib\/core\/Parser.php(291): lib\\core\\Parser->group()\n#7 \/home\/customer\/www\/circles.icu\/public_html\/dmxConnectLib\/lib\/core\/Parser.php(271): lib\\core\\Parser->unary()\n#8 \/home\/customer\/www\/circles.icu\/public_html\/dmxConnectLib\/lib\/core\/Parser.php(261): lib\\core\\Parser->multiplicative()\n#9 \/home\/customer\/www\/circles.icu\/public_html\/dmxConnectLib\/lib\/core\/Parser.php(251): lib\\core\\Parser->addictive()\n#10 \/home\/customer\/www\/circles.icu\/public_html\/dmxConnectLib\/lib\/core\/Parser.php(241): lib\\core\\Parser->bitwiseShift()\n#11 \/home\/customer\/www\/circles.icu\/public_html\/dmxConnectLib\/lib\/core\/Parser.php(231): lib\\core\\Parser->relational()\n#12 \/home\/customer\/www\/circles.icu\/public_html\/dmxConnectLib\/lib\/core\/Parser.php(221): lib\\core\\Parser->equality()\n#13 \/home\/customer\/www\/circles.icu\/public_html\/dmxConnectLib\/lib\/core\/Parser.php(211): lib\\core\\Parser->bitwiseAnd()\n#14 \/home\/customer\/www\/circles.icu\/public_html\/dmxConnectLib\/lib\/core\/Parser.php(201): lib\\core\\Parser->bitwiseXor()\n#15 \/home\/customer\/www\/circles.icu\/public_html\/dmxConnectLib\/lib\/core\/Parser.php(191): lib\\core\\Parser->bitwiseOr()\n#16 \/home\/customer\/www\/circles.icu\/public_html\/dmxConnectLib\/lib\/core\/Parser.php(179): lib\\core\\Parser->logicalAnd()\n#17 \/home\/customer\/www\/circles.icu\/public_html\/dmxConnectLib\/lib\/core\/Parser.php(163): lib\\core\\Parser->logicalOr()\n#18 \/home\/customer\/www\/circles.icu\/public_html\/dmxConnectLib\/lib\/core\/Parser.php(159): lib\\core\\Parser->conditional()\n#19 \/home\/customer\/www\/circles.icu\/public_html\/dmxConnectLib\/lib\/core\/Parser.php(104): lib\\core\\Parser->expression()\n#20 \/home\/customer\/www\/circles.icu\/public_html\/dmxConnectLib\/lib\/App.php(277): lib\\core\\Parser->parse('query_list_site...', NULL)\n#21 \/home\/customer\/www\/circles.icu\/public_html\/dmxConnectLib\/modules\/core.php(147): lib\\App->parseObject('{{query_list_si...')\n#22 \/home\/customer\/www\/circles.icu\/public_html\/dmxConnectLib\/lib\/App.php(223): modules\\core->setsession(Object(stdClass), 'fb_id', NULL)\n#23 \/home\/customer\/www\/circles.icu\/public_html\/dmxConnectLib\/lib\/App.php(195): lib\\App->execSteps(Object(stdClass))\n#24 \/home\/customer\/www\/circles.icu\/public_html\/dmxConnectLib\/lib\/App.php(163): lib\\App->execSteps(Array)\n#25 \/home\/customer\/www\/circles.icu\/public_html\/dmxConnectLib\/lib\/App.php(152): lib\\App->exec(Object(stdClass), false)\n#26 \/home\/customer\/www\/circles.icu\/public_html\/dmxConnectLib\/lib\/App.php(113): lib\\App->exec(Object(stdClass), false)\n#27 \/home\/customer\/www\/circles.icu\/public_html\/dmxConnect\/api\/general\/list_site_details.php(7): lib\\App->define(Object(stdClass))\n#28 {main}"
}

Is there any upgrading to support PHP 8.1 planned or available?

Will check our code to handle it, but you are passing a null value to the encrypt formatter which is also not correct and having this error is a good reminder that you should handle the input better.

Thanks @patrick - this is fairly old code so I'd need to look into it as as far as I can remember I'm not using the encrypt formatted at all in there.
If I turn on PHP 8.2 or 8.1 on my dev environment, the first message I get is:
{"code":0,"file":"\/volume1\/web\/circles\/dmxConnectLib\/lib\/db\/Connection.php","line":87,"message":"Undefined constant PDO::MYSQL_ATTR_INIT_COMMAND","trace":"#0
which seems to be within the Wappler API.

There are no errors with PHP 8.0.x.

Thanks!

What for server do you run PHP with? The error is from the MySQL driver. After some google search it seems that it was a bug in PHP 5.3 but I also found some issues from users that have the same error message with PHP 8.2. It seems to be related to the PHP/MySQL driver installation.

You can comment out the code on line 87 of dmxConnectLib/lib/db/Connection.php and see if Server Connect then still runs fine. The code sets the database charset to correctly handle utf-8 characters.

I'm using Apache 2.4, and when I comment line 87, another error in line 105 does indeed point to a driver:

  "code": 0,
  "file": "/volume1/web/circles/dmxConnectLib/lib/db/Connection.php",
  "line": 105,
  "message": "could not find driver",
  "trace": "#0 /volume1/web/circles/dmxConnectLib/lib/db/Connection.php(105): PDO->__construct('mysql:host=127....', 'root', 'mDsoleil9678+', Array)\n#1 /volume1/web/circles/dmxConnectLib/lib/db/Connection.php(25): lib\\db\\Connection->__construct(Object(lib\\App), Object(stdClass), 'scrud')\n#2 /volume1/web/circles/dmxConnectLib/modules/dbconnector.php(108): lib\\db\\Connection::get(Object(lib\\App), 'scrud')\n#3 /volume1/web/circles/dmxConnectLib/lib/App.php(223): modules\\dbconnector->single(Object(stdClass), 'select_site', Array)\n#4 /volume1/web/circles/dmxConnectLib/lib/App.php(195): lib\\App->execSteps(Object(stdClass))\n#5 /volume1/web/circles/dmxConnectLib/lib/App.php(163): lib\\App->execSteps(Array)\n#6 /volume1/web/circles/dmxConnectLib/lib/App.php(152): lib\\App->exec(Object(stdClass), false)\n#7 /volume1/web/circles/dmxConnectLib/lib/App.php(113): lib\\App->exec(Object(stdClass), false)\n#8 /volume1/web/circles/dmxConnect/api/general/list_site_details.php(8): lib\\App->define(Object(stdClass))\n#9 {main}"
}```

Well seems the MySQL driver for PDO is not enabled on your local server. What are using as local server WAMP, docker or the Wappler Local Server?

Ask your hosting provider to enable MySQL PDO because it broke with the PHP upgrade

Or if you want to do it yourself, you have to go to your control panel's PHP configuration and enable the MySQL PDO extension

Thanks both for the pointers, the mysql_pdo extension was indeed not enabled. I apologize, I should have picked this up myself, I'm quite rusty as I've spent more time in medical facilities than at home in the last year.

Once I enabled the driver I ensured not to pass empty values to the encrypt formatter and that resolved the issue.

At this point I'm not sure if passing empty values can be warned about from Wappler at it depends on the API logic, so I'll leave it to you @patrick to determine best/next steps.

Thanks all for the help.

I don't think anyone coming from behavioural science background is expected to know about MySQL PDO :wink:

Hope your health is better now!

You just have to use a .default('') formatter before the encryption formatter

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.