Interface Specification problems

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.