Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

How does PHP read the PHP whole script / file?

General discussions related to php

Moderators: macek, egami, gesf

How does PHP read the PHP whole script / file?

Postby cheaterastic » Sat Apr 13, 2013 9:19 am

How does PHP read his PHP script?

Look at this Image
Image

Do my image is correct? Please correct me.
Do PHP will skip the value/varchar and he will just call it during the ECHO ?
Do PHP will read the function line but he will skip reading inside of it except ECHOING it?

Or he will read all lines from very beginning until to the end ?
cheaterastic
New php-forum User
New php-forum User
 
Posts: 2
Joined: Sat Apr 13, 2013 8:57 am

Re: How does PHP read the PHP whole script / file?

Postby Strider64 » Sat Apr 13, 2013 11:10 am

To answer your question the function can go anywhere (though most programmers put functions at the top), so that tells you what you are doing with that script. ;-)

echo is just outputting the variable, the script would still run correctly without it.

and test1($var1); is just calling the function....

The only thing that would make it throw a tizzy is if you delete $var1 = "1st var"; for then you would have an undefine var.
User avatar
Strider64
New php-forum User
New php-forum User
 
Posts: 44
Joined: Sat Mar 23, 2013 8:24 am

Re: How does PHP read the PHP whole script / file?

Postby cheaterastic » Sat Apr 13, 2013 11:54 am

Strider64 wrote:To answer your question the function can go anywhere (though most programmers put functions at the top), so that tells you what you are doing with that script. ;-)

echo is just outputting the variable, the script would still run correctly without it.

and test1($var1); is just calling the function....

The only thing that would make it throw a tizzy is if you delete $var1 = "1st var"; for then you would have an undefine var.


OK, Thanks for answer, yeah I learn from your answer.

BTW, I just wanted to know if the PHP read all the lines of PHP scripts. Do some line will be skipped if it is useless, like just defending from ECHO (outputting) to call back to any $varchar that is stated to ECHO line ???

Like if I make lot of $varchar with different name of $varchar,$varchar2, etc and they are in 10,000 lines with different values, and only 1 echo calling only on 1 $varchar. Do it will use big CPU Usage or some memory?

How about if 1 $varchar and 10,000 lines of ECHO calling the $varchar, do they will have the same CPU Usage?

I am just careful of including PHP file with lot of useless lines / $varchar.
cheaterastic
New php-forum User
New php-forum User
 
Posts: 2
Joined: Sat Apr 13, 2013 8:57 am

Re: How does PHP read the PHP whole script / file?

Postby Strider64 » Sat Apr 13, 2013 5:36 pm

Since PHP is a scripting language every line of code is evaluated, that is if I'm understanding you question. The only time it doesn't from a programmers point of view is if it is in a function.

for example
Code: Select all
function first() {
   $var1 = "Hello, World!";
   echo $var1;
}


if it is never called it will never run; however, I'm sure some memory (relatively small compared to today's processing power :D ) is put aside for the function in case it is ever called. I just like to add, that I'm sure you won't run into that problem, for once you get the hang of writing loops, conditions, functions, classes, etc.. you find yourself writing less code.
User avatar
Strider64
New php-forum User
New php-forum User
 
Posts: 44
Joined: Sat Mar 23, 2013 8:24 am

Re: How does PHP read the PHP whole script / file?

Postby seandisanti » Mon Apr 15, 2013 7:29 pm

at run time, the entire script including functions and includes are evaluated, even if not executed. For proof, just run a script that contains an error in an orphan (uncalled) block like this:
Code: Select all
<?php
function blah(){
    
x
}
echo 
'error ignored';
 

You'll receive a parse error instead of the echo'd 'error ignored'
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 773
Joined: Mon Oct 01, 2012 12:32 pm


Return to PHP General

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron