Home > Backend Development > PHP Tutorial > ci - Is there a problem with the CodeIgniter framework Router.php source code?

ci - Is there a problem with the CodeIgniter framework Router.php source code?

WBOY
Release: 2023-03-03 10:40:02
Original
1046 people have browsed it

In the systemcoreRouter.php file of the ci framework, the starting code of line 132 is as follows:

<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']);
    }</code>
Copy after login
Copy after login

First of all, the first line:
is_array($routing) && isset($routing['directory']) && $this->set_directory($routing['directory']);
I'm not sure if it works like this Meaning, if no judgment is added to the result (true or false) of such a line of expression, what is the purpose of the result (true or false)?
In addition, in the if judgment statement, empty is used to judge the two results. I also think there is no Meaning, if you don’t want to make a judgment, do you have any thoughts on writing it like this?
Please give me some advice.

Reply content:

In the systemcoreRouter.php file of the ci framework, the starting code of line 132 is as follows:

<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']);
    }</code>
Copy after login
Copy after login

First of all, the first line:
is_array($routing) && isset($routing['directory']) && $this->set_directory($routing['directory']);
I'm not sure if it works like this Meaning, if no judgment is added to the result (true or false) of such a line of expression, what is the purpose of the result (true or false)?
In addition, in the if judgment statement, empty is used to judge the two results. I also think there is no Meaning, if you don’t want to make a judgment, do you have any thoughts on writing it like this?
Please give me some advice.

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

</code>
Copy after login
Do you know that the symbol

&& is true + true?
In other words, the first and the second must be executed successfully before the third one will be executed. All three must be executed successfully, otherwise it will not be executed. We can change it to another way of writing:

<code>if (is_array($routhing) && isset($routing['directory'])) {
    $this->set_directory($routing['directory']);
}
</code>
Copy after login

Is your thinking very clear?

Why do you do this? && Do this?

<code>1、因为不涉及复杂的语句
2、简洁
3、直观、可读性强</code>
Copy after login

<code class="php">// && vs ||
!isset($a) && $a=1;
echo $a;//1
isset($a) || $a =2;
echo $a;//1</code>
Copy after login
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template