What is PHP core?

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

abalfazl
Forum Commoner
Posts: 71
Joined: Mon Sep 05, 2005 10:05 pm

Re: What is PHP core?

Post 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?
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: What is PHP core?

Post 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.
abalfazl
Forum Commoner
Posts: 71
Joined: Mon Sep 05, 2005 10:05 pm

Re: What is PHP core?

Post by abalfazl »

Thank you very much indeed.

I understand something,

May you tell me a simple definition for PHP core?
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: What is PHP core?

Post 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.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: What is PHP core?

Post 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.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: What is PHP core?

Post by Jonah Bron »

Interesting... that's the only way I can think of. I might have to look into this.

Cheers
Post Reply