About the php code running sequence

Source: Internet
Author: User
If you have any questions about the php code running sequence, please help me answer the following questions. thank you.
A set of code is downloaded from the Internet. The following admin. php file:
How did the following code run?
That is, for example, when will the code "if ($ device = 'iPad ')" be run?

I want to express the following meanings:
In php code, you can see the following:
So when will it run to if (xxw) xxxcc?
If the function xxxc () is not run, will it run to if (xxw) xxxcc? (I don't know if it is clear)

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, 'Your authorization ');
}


If ($ device = 'iPad ')
SetMe ('ABC', 'width = device-width, initial-scale = 1.0, minimum-scale = 1.0, maximum-scale = 1.0, user-scalable = no ');

SetTitle ('background management ');

?>


Reply to discussion (solution)

Code running sequence from top to bottom

Code running sequence from top to bottom



Thank you, microlab2009.
Please try again.
In fact, what I want to say is:
Function HavePermissions ($ pid ){
.....
If ($ GLOBALS ['user']-> HavePermissions ($ pid ))
Return true;
SetLocation (-1, 'Your authorization ');
}


If the above function does not run, will the following code 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 ('background management ');

Function HavePermissions ($ pid ){
It is a function definition and is irrelevant to the running sequence.

Function HavePermissions ($ pid ){
It is a function definition and is irrelevant to the running sequence.



Thank you for your reply.

I also want to confirm, according to your meaning, can I understand the following code?

The following code runs in sequence:

$ Act = Get ('Act '); -- "if (! Isset ($ act {0}) {}--> if ($ device = 'iPad ')-> SetTitle ('background management ');

That is, if ($ device = 'iPad') is not running the function HavePermissions (), you can directly jump to the code


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, 'Your authorization ');
}

If ($ device = 'iPad ')
SetMe ('ABC', 'width = device-width, initial-scale = 1.0, minimum-scale = 1.0, maximum-scale = 1.0, user-scalable = no ');

SetTitle ('background management ');

?>

Not HavePermissions ()
Function HavePermissions () does not affect the execution sequence.

If function HavePermissions () is not run ()
If HavePermissions () exists after (or before), isn't it a mess?

Not HavePermissions ()
Function HavePermissions () does not affect the execution sequence.

If function HavePermissions () is not run ()
If HavePermissions () exists after (or before), isn't it a mess?



Thank you for your reply.

I still have some questions.

For example, a function abc is defined, which is not called on the admin. php page. Or simply defined, but not
Used.

Can the running sequence of the following code be understood in this way?

$ Act = Get ('Act '); if (! Isset ($ act {0}) {}-- "if ($ device = 'iPad ')


That is to say, after running this if (! Isset ($ act {0}) {} directly jumps to if ($ device = 'iPad '). Instead of running this function abc ()
Can this be understood?

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 ('background management ');

?>

Definition is definition, and execution is execution. There are two different concepts.
Don't mess up your own ideas.

Although php allows you to write the code that is called before and defined after
However, this is the principle that php should first define and then use internally.
That is to say, during execution, all definitions have been executed

Definition is definition, and execution is execution. There are two different concepts.
Don't mess up your own ideas.

Although php allows you to write the code that is called before and defined after
However, this is the principle that php should first define and then use internally.
That is to say, during execution, all definitions have been executed



Thank you for your reply.

I still want to ask a question at the end. I have a lot of questions if I try again. Thank you!

$ Act = Get ('Act ');

If (! Isset ($ act {0 })){
$ Act = 'PDA ';}

How should I understand isset ($ act {0}) in the if statement? In particular, what does $ act {0} mean by this 0 code?
Isset ($ act {0}) indicates whether the variable at location 0th in act () is defined and exists. I really don't want to say this.



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

$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.