The interface should return to the unified format, not as the caller's judgment based on the text, to be based on the status code

Source: Internet
Author: User

/**
*
* Check if mobile phone number is available
* @param $cellphone Mobile phone number
*/
Public Function Checkphone ($cellphone) {
$cellphone = Trim ($cellphone);
if (Inputcheck::checkcellphone ($cellphone) = = False)
throw new Apiexception (4001023);
$member = Member::findfirstbycellphone ($cellphone);

Todo by Wangtao
The return method here is not uniform, can register or can not register the return of a text, so that the caller is difficult to judge, once the text changes will make the caller code becomes cumbersome.
Should be returned in the form of a status code, even if True or false is better.
The hint message should only be used as an auxiliary form of an interface and cannot be relied upon by the caller.
I do not know what applications are already calling this interface, if you want to modify, a new interface to ensure unity. If it is determined that there is no call, you can delete the interface, avoid affecting the successor, resulting in a style of disunity
if (!empty ($member)) {
$this->response->render (' mobile phone number has been registered, change a mobile phone number! ')///return false will be better, in favor of caller's code judgment
} else {
$this->response->render (' mobile phone number can be registered ');//success should return a success status code, such as True
}
}

The interface should return to the unified format, not as the caller's judgment based on the text, to be based on the status code

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.