-
Notifications
You must be signed in to change notification settings - Fork 772
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check if property is initialized before getting its value
This commit also removed the use of "setAccessible", since it's not neccessary after PHP 8.1. Co-authored-by: Henrique Moody <[email protected]>
- Loading branch information
1 parent
6e3ed94
commit 8d7d783
Showing
4 changed files
with
31 additions
and
2 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 |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
use function property_exists; | ||
|
||
/** | ||
* Validates an object attribute, event private ones. | ||
* Validates an object attribute, even private ones. | ||
* | ||
* @author Alexandre Gomes Gaigalas <[email protected]> | ||
* @author Emmerson Siqueira <[email protected]> | ||
|
@@ -38,7 +38,9 @@ public function __construct(string $reference, ?Validatable $rule = null, bool $ | |
public function getReferenceValue($input) | ||
{ | ||
$propertyMirror = new ReflectionProperty($input, (string) $this->getReference()); | ||
$propertyMirror->setAccessible(true); | ||
if ($propertyMirror->isInitialized($input) === false) { | ||
return null; | ||
} | ||
|
||
return $propertyMirror->getValue($input); | ||
} | ||
|
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,17 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright (c) Alexandre Gomes Gaigalas <[email protected]> | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Respect\Validation\Test\Stubs; | ||
|
||
final class WithUninitialized | ||
{ | ||
public string $initialized = 'foo'; | ||
|
||
public string $uninitialized; | ||
} |
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