-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(agent): Resolve mysqli deprecation warnings on PHP 8.1+ (#750)
Certain wrapped mysqli functions allow null values to be passed for optional values on PHP 8.1+. This PR fixes the issue of the agent not properly expecting these null values in zpp resulting in deprecation warnings being thrown.
- Loading branch information
1 parent
9db916e
commit 51759a5
Showing
6 changed files
with
276 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/*DESCRIPTION | ||
The agent should not cause a deprecation warning to be thrown when passing null | ||
to optional arguments for mysqli_connect on PHP 8.1+ | ||
*/ | ||
|
||
/*SKIPIF | ||
<?php require("skipif.inc"); | ||
if (version_compare(PHP_VERSION, "8.1", "<")) { | ||
die("skip: Deprecation warning PHP 8.1+ specific\n"); | ||
} | ||
*/ | ||
|
||
/*INI | ||
error_reporting = E_DEPRECATION | ||
*/ | ||
|
||
/*EXPECT | ||
*/ | ||
|
||
require_once(realpath (dirname ( __FILE__ )) . '/../../include/config.php'); | ||
|
||
$link = mysqli_connect(null, null, null, null, null, null); | ||
|
||
if (mysqli_connect_errno()) { | ||
echo mysqli_connect_error() . "\n"; | ||
exit(1); | ||
} | ||
|
||
mysqli_close($link); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/*DESCRIPTION | ||
The agent should not cause a deprecation warning to be thrown when passing null | ||
to optional arguments for mysqli::__construct on PHP 8.1+ | ||
*/ | ||
|
||
/*SKIPIF | ||
<?php require("skipif.inc"); | ||
if (version_compare(PHP_VERSION, "8.1", "<")) { | ||
die("skip: Deprecation warning PHP 8.1+ specific\n"); | ||
} | ||
*/ | ||
|
||
/*INI | ||
error_reporting = E_DEPRECATION | ||
*/ | ||
|
||
/*EXPECT | ||
*/ | ||
|
||
require_once(realpath (dirname ( __FILE__ )) . '/../../include/config.php'); | ||
|
||
$link = new mysqli(null, null, null, null, null, null); | ||
|
||
if (mysqli_connect_errno()) { | ||
echo mysqli_connect_error() . "\n"; | ||
exit(1); | ||
} | ||
|
||
mysqli_close($link); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/*DESCRIPTION | ||
The agent should not cause a deprecation warning to be thrown when passing null | ||
to optional arguments for mysqli::real_connect on PHP 8.1+ | ||
*/ | ||
|
||
/*SKIPIF | ||
<?php require("skipif.inc"); | ||
if (version_compare(PHP_VERSION, "8.1", "<")) { | ||
die("skip: Deprecation warning PHP 8.1+ specific\n"); | ||
} | ||
*/ | ||
|
||
/*INI | ||
error_reporting = E_DEPRECATION | ||
*/ | ||
|
||
/*EXPECT | ||
*/ | ||
|
||
require_once(realpath (dirname ( __FILE__ )) . '/../../include/config.php'); | ||
|
||
$link = mysqli_init(); | ||
$link->options(MYSQLI_OPT_CONNECT_TIMEOUT, 10); | ||
$link->real_connect(null, null, null, null, null, null); | ||
|
||
if (mysqli_connect_errno()) { | ||
echo mysqli_connect_error() . "\n"; | ||
exit(1); | ||
} | ||
|
||
mysqli_close($link); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/*DESCRIPTION | ||
The agent should not cause a deprecation warning to be thrown when passing null | ||
to optional arguments for mysqli_real_connect on PHP 8.1+ | ||
*/ | ||
|
||
/*SKIPIF | ||
<?php require("skipif.inc"); | ||
if (version_compare(PHP_VERSION, "8.1", "<")) { | ||
die("skip: Deprecation warning PHP 8.1+ specific\n"); | ||
} | ||
*/ | ||
|
||
/*INI | ||
error_reporting = E_DEPRECATION | ||
*/ | ||
|
||
/*EXPECT | ||
*/ | ||
|
||
require_once(realpath (dirname ( __FILE__ )) . '/../../include/config.php'); | ||
|
||
$link = mysqli_init(); | ||
mysqli_options($link, MYSQLI_OPT_CONNECT_TIMEOUT, 10); | ||
|
||
mysqli_real_connect($link, null, null, null, null, null, null); | ||
|
||
if (mysqli_connect_errno()) { | ||
echo mysqli_connect_error() . "\n"; | ||
exit(1); | ||
} | ||
|
||
mysqli_close($link); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/*DESCRIPTION | ||
The agent should not cause a deprecation warning to be thrown when passing null | ||
to optional arguments for mysqli_stmt:__construct on PHP 8.1+ | ||
*/ | ||
|
||
/*SKIPIF | ||
<?php require("skipif.inc"); | ||
if (version_compare(PHP_VERSION, "8.1", "<")) { | ||
die("skip: Deprecation warning PHP 8.1+ specific\n"); | ||
} | ||
*/ | ||
|
||
/*INI | ||
error_reporting = E_ALL | ||
*/ | ||
|
||
/*EXPECT | ||
STATISTICS | ||
*/ | ||
|
||
require_once(realpath (dirname ( __FILE__ )) . '/../../include/config.php'); | ||
|
||
function test_stmt_prepare($link) | ||
{ | ||
$stmt = new mysqli_stmt($link, null); | ||
$name = 'STATISTICS'; | ||
|
||
$query = "SELECT TABLE_NAME FROM information_schema.tables WHERE table_name=?"; | ||
if (FALSE === $stmt->prepare($query) || | ||
FALSE === $stmt->bind_param('s', $name) || | ||
FALSE === $stmt->execute() || | ||
FALSE === $stmt->bind_result($name)) { | ||
echo mysqli_stmt_error($stmt) . "\n"; | ||
mysqli_stmt_close($stmt); | ||
return; | ||
} | ||
|
||
while (mysqli_stmt_fetch($stmt)) { | ||
echo $name . "\n"; | ||
} | ||
|
||
mysqli_stmt_close($stmt); | ||
} | ||
|
||
$link = mysqli_connect($MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWD, $MYSQL_DB, $MYSQL_PORT, $MYSQL_SOCKET); | ||
if (mysqli_connect_errno()) { | ||
echo mysqli_connect_error() . "\n"; | ||
exit(1); | ||
} | ||
|
||
test_stmt_prepare($link); | ||
mysqli_close($link); | ||
|