How to set PHP Universal return value

Source: Internet
Author: User
This article mainly introduces the PHP general return value of the setting method of the detailed, interested in the friend's reference, I hope to be helpful to everyone.

Encountered a good PHP code. Record it.

When you write PHP code, you often encounter the need to return the value of the situation, you can set the return value of the uniform format.

Here's a good example.

Configuration Class Return.conf.php

<?phpdefine ("Return_val", "Return Array" (' Code ' = 0, ' msg ' = ' = ', ' data ' = '); "); Define ("Return_success",    0); Define ("Return_runtime_err",  1); Define ("Return_file_not_exist", 2); class returnconf{public  static function Commonreturn () {    return eval (return_val);  }  }? >

testing, using test.php

<?phprequire_once ("Return.conf.php"), function Get_file_line ($filename) {  $result = Returnconf::commonreturn ();    $cmd = "Wc-l $filename | awk ' {print '} ';  EXEC ($cmd, $output, $code);  if (return_success!== $code) {    $result [' code '] = Return_runtime_err;    $result [' msg '] = "exec $cmd err";    return $result;   }    $result [' data '] = $output [0];  return $result;} Print_r (Get_file_line ("test.php"));? >

The above is the whole content of this article, I hope that everyone's study has helped.


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.