Generally, the integer and floating point types are output as strings. do you want to process this type? The Laravel framework is currently in use. My idea is to define the data type on each Model side, and then process the data in a unified manner when the Model is output. what's the best...
Generally, the integer and floating point types are output as strings. do you want to process this type?
The Laravel framework is currently in use.
My idea is to define the data type on each Model side, and then process the data in a unified manner when the Model is output. Is there any good method.
Reply content:
Generally, the integer and floating point types are output as strings. do you want to process this type?
The Laravel framework is currently in use.
My idea is to define the data type on each Model side, and then process the data in a unified manner when the Model is output. Is there any good method.
PHP is a weak language, so this situation is common.
Generally, interaction with js or other weak languages is not a problem.
Some problems may occur in strong languages such as Ios and Android.
1. write an api for unified processing. perform a unified processing before the output. if it is an int, use intval for conversion. if it is null, it is null, it is a null string, it is "", this should be noted in the strong type.
2. interaction side, Ios, Android, etc. it is best to also perform type verification. you can perform type conversion and fault tolerance. if the type returned by the interface is not incorrect, the program will crash.
It is best to deal with both.
This has nothing to do with the framework. PHP is of a weak type. Therefore, the data format is not standard when JSON is returned. Currently, the interfaces for returning JSON data are manually formatted on the outermost side.
Strval (xxx) // formatted as a string intval (xxx) // formatted as an integer floatval (xxx) // formatted as a floating-point number boolval (xxx) // formatted as a floating-point number
Thank you for your invitation. it is clear that php is weak. you can use a program to process the data you want to accept or the data returned to your client, ensure data integrity and accuracy. You can define a class or method to process the floating point, integer, and other data you mentioned. In short, it is enough to ensure that the interface security data is correct.
First, let's talk about my results.
It is not converted to a string.
Is your data originally a string.
My php version: 5.5.34
Laravel Framework version: 5.2.22
By the way, I think the processing should be unified when the controller returns.