Do they know it’s C in PHP 🎄

Just the Gist
Behind the scenes, PHP uses the C programming language to do its magic.

It’s C in a nice wrapper 🎁

While we write PHP, behind the scene it is all being interpreted as C. When we write pi(), what’s going on? Behind the scenes…


This content originally appeared on DEV Community and was authored by Anders Björkland

Just the Gist

Behind the scenes, PHP uses the C programming language to do its magic.

It's C in a nice wrapper 🎁

While we write PHP, behind the scene it is all being interpreted as C. When we write pi(), what's going on? Behind the scenes it's mapped to this code in the C programming language:

PHP_FUNCTION(pi)
{
    ZEND_PARSE_PARAMETERS_NONE();

    RETURN_DOUBLE(M_PI);
}

M_PI is a constant defined in the php_math.h header file:

#ifndef M_PI
#define M_PI           3.14159265358979323846  /* pi */
#endif

And guess what? We can also call the constant M_PI from PHP and get the same result. This is really not a surprise, as we can see that the function just returns that constant.

Interpretation skills

So how is <?php echo pi() ?> able to use the C language to return to us the value of M_PI? It's because of the Zend Engine. This interpreter has been a part of PHP since version 4, but how does it work? It's a bit like a compiler and a runtime environment rolled up into one:

  1. It analyzes the code.
  2. Then it translates it into C.
  3. And finally it executes the translated code.

☝️ The Zend Engine is a C extension that is part of PHP. You don't have to go chasing after it on the Web if you've already got PHP for your machine. You will have all you need to run your scripts!

What about you?

What are your thoughts on the C programming language? Would you be willing to try it out, maybe even becoming a core contributor? Leave a comment below! ✍

Further Reading


This content originally appeared on DEV Community and was authored by Anders Björkland


Print Share Comment Cite Upload Translate Updates
APA

Anders Björkland | Sciencx (2021-12-03T06:55:17+00:00) Do they know it’s C in PHP 🎄. Retrieved from https://www.scien.cx/2021/12/03/do-they-know-its-c-in-php-%f0%9f%8e%84/

MLA
" » Do they know it’s C in PHP 🎄." Anders Björkland | Sciencx - Friday December 3, 2021, https://www.scien.cx/2021/12/03/do-they-know-its-c-in-php-%f0%9f%8e%84/
HARVARD
Anders Björkland | Sciencx Friday December 3, 2021 » Do they know it’s C in PHP 🎄., viewed ,<https://www.scien.cx/2021/12/03/do-they-know-its-c-in-php-%f0%9f%8e%84/>
VANCOUVER
Anders Björkland | Sciencx - » Do they know it’s C in PHP 🎄. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/12/03/do-they-know-its-c-in-php-%f0%9f%8e%84/
CHICAGO
" » Do they know it’s C in PHP 🎄." Anders Björkland | Sciencx - Accessed . https://www.scien.cx/2021/12/03/do-they-know-its-c-in-php-%f0%9f%8e%84/
IEEE
" » Do they know it’s C in PHP 🎄." Anders Björkland | Sciencx [Online]. Available: https://www.scien.cx/2021/12/03/do-they-know-its-c-in-php-%f0%9f%8e%84/. [Accessed: ]
rf:citation
» Do they know it’s C in PHP 🎄 | Anders Björkland | Sciencx | https://www.scien.cx/2021/12/03/do-they-know-its-c-in-php-%f0%9f%8e%84/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.