Ci-codeigniter Frame router.php Is there a problem with the source code?

Source: Internet
Author: User
Tags codeigniter
In the CI framework's systemcorerouter.php file, the line132 line begins with the following code:

    is_array($routing) && isset($routing['directory']) && $this->set_directory($routing['directory']);    $this->_set_routing();    // Set any routing overrides that may exist in the main index file    if (is_array($routing))    {        empty($routing['controller']) OR $this->set_class($routing['controller']);        empty($routing['function'])   OR $this->set_method($routing['function']);    }

First, the first line of:
Is_array ($routing) && isset ($routing [' directory ']) && $this->set_directory ($routing [' Directory ' ]);
I'm not sure if it makes sense, so the result of a line expression (true or false) does not add judgment, what is the result (true or false)?
In addition, in the IF judgment statement, using empty to determine the two results, I also think there is no sense, if not to make a judgment, so write what ideas?
Please also advise.

Reply content:

In the CI framework's systemcorerouter.php file, the line132 line begins with the following code:

    is_array($routing) && isset($routing['directory']) && $this->set_directory($routing['directory']);    $this->_set_routing();    // Set any routing overrides that may exist in the main index file    if (is_array($routing))    {        empty($routing['controller']) OR $this->set_class($routing['controller']);        empty($routing['function'])   OR $this->set_method($routing['function']);    }

First, the first line of:
Is_array ($routing) && isset ($routing [' directory ']) && $this->set_directory ($routing [' Directory ' ]);
I'm not sure if it makes sense, so the result of a line expression (true or false) does not add judgment, what is the result (true or false)?
In addition, in the IF judgment statement, using empty to determine the two results, I also think there is no sense, if not to make a judgment, so write what ideas?
Please also advise.

is_array($routing) && isset($routing['directory']) && $this->set_directory($routing['directory']);

&&This symbol knows it's true + true right.
That is, 第一个 and 第二个 must be successful to execute the third, the three are to execute the success, no this will not be executed. We can change the wording:

if (is_array($routhing) && isset($routing['directory'])) {    $this->set_directory($routing['directory']);}

The idea is clear.

Why do you do this && ?

1、因为不涉及复杂的语句2、简洁3、直观、可读性强

// && vs ||!isset($a) && $a=1;echo $a;//1isset($a) || $a =2;echo $a;//1
  • 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.