-
Notifications
You must be signed in to change notification settings - Fork 16k
feat(php): Add PHP typehints for setters and remove redundant GPBUtil checks #25296
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
Conversation
… checks This commit modifies the php_generator.cc file to: - Add PHP typehints to setter method signatures for all types (for 64-bit integers, the type hint is 'int|string' to maintain compatibility with 32-bit systems) - Remove redundant GPBUtil::check... for primitive types (the PHP type hint provides sufficient validation) - Retain GPBUtil::check... for 32 and 64-bit integers, strings (for UTF-8 validation), messages, enums, maps, and repeated fields
|
Looks like you have some test failures on 32-bit and aarch64 :( |
|
@mkruskal-google all passing now! |
|
Looks like still failing? |
|
@anandolee no, they're passing.. looks like the job was stuck |
|
@mkruskal-google one thing worth consideration - the calls to public static function checkFloat(&$var)
{
if (is_float($var) || is_numeric($var)) {
$var = unpack("f", pack("f", $var))[1];
} else {
throw new \Exception("Expect float.");
}
}
public static function checkDouble(&$var)
{
if (is_float($var) || is_numeric($var)) {
$var = floatval($var);
} else {
throw new \Exception("Expect float.");
}
}
public static function checkBool(&$var)
{
if (is_array($var) || is_object($var)) {
throw new \Exception("Expect boolean.");
}
$var = boolval($var);
}
|
|
I have added back breaking change implicationAnyone who is running gencode in strict mode (e.g. |
This PR modifies
php_generator.ccto:int|stringto maintain compatibility with 32-bit systems)GPBUtil::check...for primitive types and messages (the PHP type hint provides sufficient validation)GPBUtil::check...for 32 and 64-bit integers, strings (for UTF-8 validation), enums, maps, and repeated fieldsAdditionally makes the following changes:
trueandfalse(instead ofTrueandFalse)