Page 2 of 2

Re: What is PHP core?

Posted: Sat Sep 25, 2010 7:19 am
by abalfazl
I think he wants help visualizing the parse tree that the php core seems like it would have to build.
Right!

Look at this code:

Code: Select all

<?php
$my_string = "Hello Bob.  My name is: ";
$my_number = 4;
$my_letter = a;
echo $my_string;
echo $my_number;
echo $my_letter;
?>

I want to know what happened in PHP core when this code runs?

Re: What is PHP core?

Posted: Sun Sep 26, 2010 8:54 pm
by Jonah Bron
Here's a very simplified version of what might happen while parsing. Each of these steps are in a loop.

loop through each letter

[syntax]letter = <
Oh, this might be the beginning of some php code...

letter = ?
Yes! It is some php code for me to parse...

letter = p
Okay, this guy probably isn't using short tags.

letter = h
Yup, looks like it...

letter = p
Definitely.

letter = \n
Okay, let's start parsing!

letter = $
okay, looks like he's about to define a variable

letter = m
okay, still reading the var name...

...

letter = [space]
Okay, he's defining a variable called $my_string. What's inside of it I wonder?

letter = =
Oh, the value is coming!

letter = [space]
Next.

letter = "
Great, it's a string.

letter = H
okay, just part of the string.

...

letter = "
this quote hasn't been escaped, so it must be the string terminator.

letter = ;
End of line! Phew, next operation.

...

letter = e
Might be a keyword, or a function. Let's see...

letter = c
Might be a function. Lets see...

letter = h
ditto

letter = o
Could be "echo", but the function name's not over yet...

letter = [space]
Okay, so it is echo. Lets output anything after this.

letter = $
Looks like I'm supposed to echo a variable.

letter = m
Not sure what variable it is yet...

...

letter = g
Could be $my_string yet, but the name's not over yet.

letter = ;
It is $my_string. I'll just output that.[/syntax]

etc.

Re: What is PHP core?

Posted: Mon Sep 27, 2010 12:24 am
by abalfazl
Thank you very much indeed.

I understand something,

May you tell me a simple definition for PHP core?

Re: What is PHP core?

Posted: Mon Sep 27, 2010 8:35 am
by mikosiko
josh posted several post ago a couple links for you to search... maybe you didn't search/read carefully....

here is another link that could help you to find some answers
http://devzone.zend.com/node/view/id/1021
but... if happens that you don't look carefully here is some extract from that

"PHP's core is made up of two separate pieces. At the lowest levels you find the Zend Engine (ZE). ZE handles parsing a human-readable script into machine-readable tokens, and then executing those tokens within a process space. ZE also handles memory management, variable scope, and dispatching function calls. The other half of this split personality is the PHP core. PHP handles communication with, and bindings to, the SAPI layer (Server Application Programming Interface, also commonly used to refer to the host environment - Apache, IIS, CLI, CGI, etc). It also provides a unified control layer for safe_mode and open_basedir checks, as well as the streams layer which associates file and network I/O with userspace functions like fopen(), fread(), and fwrite()."

after this paragraph is more to read in the same page related to your questions.

Re: What is PHP core?

Posted: Mon Sep 27, 2010 11:50 pm
by josh
@Jonah Bron with all due respect, guessing isn't likely to give an accurate account of what actually happens. If it were that obvious PHP wouldn't be as unique as it is. What you wrote accurately describes what goes on in a programmer's head when he reads the code, computers think a LOT differently than a programmer though, for example you'll see above it does not parse the code itself, it parses a tokenized (byte code) representation of the code more suitable for machine consumption.

The best bet is to read their unit tests. Unit tests show you exactly whats going on, usually.

Re: What is PHP core?

Posted: Tue Sep 28, 2010 10:34 am
by Jonah Bron
Interesting... that's the only way I can think of. I might have to look into this.

Cheers