-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix the default value of $ctorArgs param in PDOStatement::fetchObject() #6937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
83ead55
Fix the default value of $ctorArgs param in PDOStatement::fetchObject()
kocsismate 9db98b5
Fix ZPP for $ctorArgs, and add test
kocsismate 71101a9
Fix memory leak
nikic 35fc760
$ctorArgs shouldn't be nullable (and should be called $constructorArgs)
kocsismate File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
99 changes: 99 additions & 0 deletions
99
ext/pdo_mysql/tests/pdo_mysql_stmt_fetchobject_ctor_args.phpt
This file contains hidden or 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,99 @@ | ||
--TEST-- | ||
MySQL PDO: PDOStatement->fetchObject() with $ctorArgs | ||
--SKIPIF-- | ||
<?php | ||
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'skipif.inc'); | ||
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); | ||
MySQLPDOTest::skip(); | ||
$db = MySQLPDOTest::factory(); | ||
|
||
try { | ||
$query = "SELECT '', NULL, \"\" FROM DUAL"; | ||
$stmt = $db->prepare($query); | ||
$ok = @$stmt->execute(); | ||
} catch (PDOException $e) { | ||
die("skip: Test cannot be run with SQL mode ANSI"); | ||
} | ||
if (!$ok) | ||
die("skip: Test cannot be run with SQL mode ANSI"); | ||
?> | ||
--FILE-- | ||
<?php | ||
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); | ||
/** @var PDO $db */ | ||
$db = MySQLPDOTest::factory(); | ||
MySQLPDOTest::createTestTable($db); | ||
|
||
$query = "SELECT id FROM test ORDER BY id ASC LIMIT 1"; | ||
$stmt = $db->prepare($query); | ||
|
||
class Foo { | ||
public int $a; | ||
public int $id; | ||
|
||
public function __construct($a) { | ||
$this->a = $a; | ||
} | ||
} | ||
|
||
class Bar { | ||
public int $id; | ||
} | ||
|
||
$stmt->execute(); | ||
try { | ||
$obj = $stmt->fetchObject(Foo::class); | ||
} catch (ArgumentCountError $exception) { | ||
echo $exception->getMessage() . "\n"; | ||
} | ||
|
||
$stmt->execute(); | ||
try { | ||
$obj = $stmt->fetchObject(Foo::class, []); | ||
} catch (ArgumentCountError $exception) { | ||
echo $exception->getMessage() . "\n"; | ||
} | ||
|
||
$stmt->execute(); | ||
$obj = $stmt->fetchObject(Foo::class, ["a" => 123]); | ||
var_dump($obj); | ||
|
||
$stmt->execute(); | ||
$obj = $stmt->fetchObject(Bar::class); | ||
var_dump($obj); | ||
|
||
$stmt->execute(); | ||
$obj = $stmt->fetchObject(Bar::class, []); | ||
var_dump($obj); | ||
|
||
try { | ||
$stmt->execute(); | ||
$obj = $stmt->fetchObject(Bar::class, ["a" => 123]); | ||
kocsismate marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} catch (Error $exception) { | ||
echo $exception->getMessage() . "\n"; | ||
} | ||
|
||
?> | ||
--CLEAN-- | ||
<?php | ||
require __DIR__ . '/mysql_pdo_test.inc'; | ||
MySQLPDOTest::dropTestTable(); | ||
?> | ||
--EXPECTF-- | ||
Too few arguments to function Foo::__construct(), 0 passed and exactly 1 expected | ||
Too few arguments to function Foo::__construct(), 0 passed and exactly 1 expected | ||
object(Foo)#%d (2) { | ||
["a"]=> | ||
int(123) | ||
["id"]=> | ||
int(1) | ||
} | ||
object(Bar)#%d (1) { | ||
["id"]=> | ||
int(1) | ||
} | ||
object(Bar)#%d (1) { | ||
["id"]=> | ||
int(1) | ||
} | ||
User-supplied statement does not accept constructor arguments |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.