Page 1 of 1

i am a newbie.. having a few small doubts..

Posted: Tue Jun 19, 2007 11:23 am
by claws
1. I learned that PHP is an interpreted language. I agree unlike C,java,cpp there is no machine code that is generated and machine code will run.
but interpreting means line by line execution.
so, say i have a syntax error on line 232 then the first 231 lines should give the corresponding output. and the line after 232( 233 onwards also should give thier corresponding outputs( i mean every thing except 232 should be executed if other lines are not depending on 232nd line) but without executing even a single line it gives syntax error(unexpected bla..bla..) why so???

2. what is the difference between mysql_fetch_rows() and mysql_fetch_array()??

3. say i have a file included.php included on 36th line of temp.php
then there will be php start tag in both the files. when i inclued included.php the senerio will be some thing like
<?php

//<36th line>
<?php

?>

?>

then it should show an error [s]becoz[/s] because there are php tags inside php tags. but it doest. why???
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:11. Please use proper, complete spelling when posting in the forums. AOL Speak, leet speak and other abbreviated wording can confuse those that are trying to help you (or those that you are trying to help). Please keep in mind that there are many people from many countries that use our forums to read, post and learn. They do not always speak English as well as some of us, nor do they know these aberrant abbreviations. Therefore, use as few abbreviations as possible, especially when using such simple words.

Some examples of what not to do are ne1, any1 (anyone); u (you); ur (your or you're); 2 (to too); prolly (probably); afaik (as far as I know); etc.
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:2. Use descriptive subjects when you start a new thread. Vague titles such as "Help!", "Why?" are misleading and keep you from receiving an answer to your question.

Posted: Tue Jun 19, 2007 11:25 am
by Benjamin
The PHP parser drops out of PHP on an include, and the tag brings it back into PHP.

Posted: Tue Jun 19, 2007 11:29 am
by superdezign
1) If PHP runs into an error, it runs into an error. Everything before it IS executed, but when it hits the error (depending on how fatal it is) it may stop.

2) mysql_fetch_array gives you a numerical array AND an associative array. mysql_fetch_rows only gives you a numerical array.

3) You can't nest PHP tags. As far as the program is concerned. the second tag is just text. It's similar to doing this is a multiline comment:

Code: Select all

/** comment
/* nested comment?
*/
*/
See? It can't nest. HTML is about nesting.. not PHP.

Posted: Wed Jun 20, 2007 12:10 am
by claws
If PHP runs into an error, it runs into an error. Everything before it IS executed, but when it hits the error (depending on how fatal it is) it may stop.
you mean. It depends on the error.
if error is more fatal it will not execute the code before and after the error.
if not code before that will be executed and after that will not???

is this correct???

but i never observed that code before the error line being executed.
can you give me some examples for 3 cases.
1. before executed
2. after only executed
3. before and after executed
4. nothing executed.

and more over my point was

php is a INTERPRETER language. means line by line parsing and execution.
then why does interpreter scan through all the code before executing???



please help me in getting my doubts cleared.

Posted: Wed Jun 20, 2007 5:14 am
by superdezign
No, you're incorrect. The code does execute all the way to the error.

Code: Select all

echo 'working<br />';
echo 'working<br />';
echo undefinedFunctionCall($foo);
echo 'still working?';
This will result in:

Code: Select all

working
working

Fatal error: Call to undefined function undefinedFunctionCall() on line 3
You're making too many assumptions, one of which being that PHP is the problem and that your code is not. PHP is different from other languages, so sometimes things have to be written a little differently. Whatever script you are referring to does, in fact, execute all the way up to the error.

Posted: Wed Jun 20, 2007 5:25 am
by volka
claws wrote: php is a INTERPRETER language. means line by line parsing and execution.
then why does interpreter scan through all the code before executing???
php parses the whole file before executing the statements. If an error occurs while parsing the file no statement of the script is executed.
claws wrote:3. say i have a file included.php included on 36th line of temp.php
then there will be php start tag in both the files. when i inclued included.php the senerio will be some thing like
<?php

//<36th line>
<?php

?>

?>
it's not a textual include before the parsing is done. If it was

Code: Select all

$x = rand(1,10);
include 'page'.$x;
or

Code: Select all

if ( 0==date('d')%2 ) {
	require 'e.php';
}
else {
	require 'o.php';
}
wouldn't work. But it does. Include() is not executed until the script execution reaches this statement.

Posted: Wed Jun 20, 2007 5:27 am
by patrikG
superdezign wrote:3) You can't nest PHP tags. As far as the program is concerned. the second tag is just text. It's similar to doing this is a multiline comment:

Code: Select all

/** comment
/* nested comment?
*/
*/
See? It can't nest. HTML is about nesting.. not PHP.
I think it's a bit confusing to compare HTML and PHP in terms of "nesting". HTML is a layouting language with no executable code. PHP is a programming language which doesn't doesn't "nest" in an HTML (i.e. visual) way. PHP "nests" in a logical way, if by "nesting" you mean statements depending on their parent-statements. You can "nest" in PHP, see recursion, loops, conditional statements etc. etc.

Posted: Wed Jun 20, 2007 5:32 am
by volka
The original question was about nesting php tags*
claws wrote:<?php

//<36th line>
<?php

?>

?>
not something like recursion ;)


----
* and the false assumption that include 'xyz' is replaced be the contents of the file xyz before parsing takes place (like it's done by a C preprocessor)

Posted: Wed Jun 20, 2007 6:30 am
by superdezign
patrikG wrote:
superdezign wrote:3) You can't nest PHP tags. As far as the program is concerned. the second tag is just text. It's similar to doing this is a multiline comment:

Code: Select all

/** comment
/* nested comment?
*/
*/
See? It can't nest. HTML is about nesting.. not PHP.
I think it's a bit confusing to compare HTML and PHP in terms of "nesting". HTML is a layouting language with no executable code. PHP is a programming language which doesn't doesn't "nest" in an HTML (i.e. visual) way. PHP "nests" in a logical way, if by "nesting" you mean statements depending on their parent-statements. You can "nest" in PHP, see recursion, loops, conditional statements etc. etc.
Hehe, I wasn't referring to code blocks or anything. All programming languages support nesting, but the comment nest comparison to the php tag nesting is a very good comparison. :P

Posted: Wed Jun 20, 2007 6:43 am
by patrikG
volka wrote:The original question was about nesting php tags*
claws wrote:<?php

//<36th line>
<?php

?>

?>
not something like recursion ;)
True, but that question was answered in the second post. What needed clarification was "nesting" which, as superdesignz said, almost all modern programming languages support.

Re: i am a newbie.. having a few small doubts..

Posted: Wed Jun 20, 2007 6:50 am
by superdezign
claws wrote:3. say i have a file included.php included on 36th line of temp.php
I must have completely missed that line. I just saw nested php tags. :lol: