Ask about the PHP code run order problem

Source: Internet
Author: User
A friend of trouble will help answer the following questions, thank you.
Downloaded a set of code on the Internet. The following admin.php files:
For the following code, how exactly does the code run?
That is, for example the following code, when will run if ($device = = ' ipad ') this code?

That means to express the following:
There are times in PHP code where you see the following:
So, when will it run to the IF (XXW) xxxcc;
If you do not run function xxxc (), it will run to the IF (XXW) xxxcc; (I don't know if I can say it clearly)

if (XXX) xxx;

function Xxxa () {

}

function Xxxc () {

}

if (XXW) xxxcc;

?>


//-----------------------------------------------

Require ' service/init.php ';

$act = Get (' act ');

if (!isset ($act {0})) {
$act = ' PDA ';

。。。
。。。
function Havepermissions ($pid) {
。。。。。
if ($GLOBALS [' User ']->havepermissions ($pid))
return true;
setlocation (-1, ' You have insufficient authority ');
}


if ($device = = ' ipad ')
Setme (' abc ', ' Width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no ');

Settitle (' backstage Management ');

?>


Reply to discussion (solution)

The code runs in order from top to bottom.

The code runs in order from top to bottom.



Thank you microlab2009 reply
Please help to reply again.
In fact, what I want to say is:
function Havepermissions ($pid) {
。。。。。
if ($GLOBALS [' User ']->havepermissions ($pid))
return true;
setlocation (-1, ' You have insufficient authority ');
}


If the above function does not run, is not the following code will not run?
if ($device = = ' ipad ')
Setme (' abc ', ' Width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no ');

Settitle (' backstage Management ');

function Havepermissions ($pid) {
is a function definition, independent of the run order

function Havepermissions ($pid) {
is a function definition, independent of the run order



Thank you xuzuning Moderator's reply

I also want to confirm that, as you mean, can I understand the following code like this?

The following code runs in the order that the results are:

$act = Get (' act '); --"If" (!isset ($act {0})) {}--and if ($device = = ' ipad '), Settitle (' admin ');

That is, without running function havepermissions () and jumping directly to the code that runs if ($device = = ' ipad ')


Require ' service/init.php ';

$act = Get (' act ');

if (!isset ($act {0})) {
$act = ' PDA ';

function Havepermissions ($pid) {
。。。。。
if ($GLOBALS [' User ']->havepermissions ($pid))
return true;
setlocation (-1, ' You have insufficient authority ');
}

if ($device = = ' ipad ')
Setme (' abc ', ' Width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no ');

Settitle (' backstage Management ');

?>

Not without running function havepermissions ()
But the function havepermissions () itself does not affect the order of execution

If there is no run function havepermissions ()
So if there is a havepermissions (or a front) there is no such a mess?

Not without running function havepermissions ()
But the function havepermissions () itself does not affect the order of execution

If there is no run function havepermissions ()
So if there is a havepermissions (or a front) there is no such a mess?



Thank you xuzuning Moderator reply

I'm still a little bit confused and want to ask.

For example, a function ABC is defined, and this function ABC is not called on this admin.php page. Or simply defined, without
Use to.

So is the order in which the following code is run to be understood?

$act = Get (' act '); if (!isset ($act {0})) {}---"if ($device = = ' ipad ')


This means that the if (!isset ($act {0})) {} is run out of the if ($device = = ' ipad '). Instead of running the function ABC ()
Can you understand this?

Require ' service/init.php ';

$act = Get (' act ');

if (!isset ($act {0})) {
$act = ' PDA ';

Function ABC ($PID) {
。。。。。

}

if ($device = = ' ipad ')
Setme (' abc ', ' Width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no ');

Settitle (' backstage Management ');

?>

Definition is definition, execution is execution. This is a two different concept.
Don't confuse yourself with your own ideas.

While PHP allows you to write calls in front, define the code after the
But this is the principle that PHP is internally guaranteed to define first, after use
That is, all definitions have been executed during execution.

Definition is definition, execution is execution. This is a two different concept.
Don't confuse yourself with your own ideas.

While PHP allows you to write calls in front, define the code after the
But this is the principle that PHP is internally guaranteed to define first, after use
That is, all definitions have been executed during execution.



Thank you xuzuning Moderator's reply

Also want to finally ask a question, trouble again reply, just contact PHP, a lot of puzzled. Thanks first.

$act = Get (' act ');

if (!isset ($act {0})) {
$act = ' PDA '; }

How should the Isset ($act {0}) in the If statement be understood? Especially $act {0} What does this 0 code mean?
Isset ($act {0}) is the definition and existence of a NO. 0-position variable in Act (). Well, I don't think it makes sense.



Isset ($act {0}) indicates whether the No. 0 position of the $act is defined and exists
Cases

$a = '; Var_dump (isset ($a {0}));
BOOL (FALSE)
  • Related Article

    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.