26

Ok: I edited my question: I heard somewhere that php language is written in C.

So what happens for example when you run a function in php such as date("Ymd"); or file_get_contents("file.txt");?

Does it translate that code to C and request to server, or does php do it?

And if it does translate it and request, that means basically it is C?

kojiro
  • 74,557
  • 19
  • 143
  • 201
avon_verma
  • 1,229
  • 3
  • 12
  • 17
  • 1
    PHP is written in C, not C++. Why don't you take a peek in the PHP source code and see for yourself? – BoltClock Jan 05 '11 at 03:13
  • no it does not translate anything into c++, although facebook developed a compiler that does translate PHP into C code, and then into machine language, called hiphop or someting like that. – dqhendricks Jan 05 '11 at 03:13
  • 1
    The PHP interpreter was written in C. A `date()` call indeed gets executed by an internal compiled library that was written in C. – Pekka Jan 05 '11 at 03:14

3 Answers3

35

That is incorrect.

If you mean the language PHP is implemented in, it is C, not C++; see the PHP wikipedia page, under Implementation Language.

That does not, however, mean that it "translates" code to C; PHP is an interpreted language.

While executing code, it does of course have to use functions written in C, since it is itself using C. However, no "translation" into C occurs; the code is simply parsed by the PHP language and the language then calls, itself, what is appropriate.

You might want to read more on interpreted languages, that should give you a better understanding.

houbysoft
  • 32,532
  • 24
  • 103
  • 156
  • I ask, why this? Where is the advantage? It is not more useful to directly code in C? – Francesco Dec 12 '15 at 23:08
  • 2
    @Francesco The advantage is that you can develop easier and faster. That's what aim interpreted language. But yes, you can perfectly code your website in C ... if you have time ... – AnonBird Sep 20 '16 at 22:38
1

In any interpreted language the language syntax is just a wrapper for functions and constructs implemented in the language the interpreted language is written in.

Achilles
  • 11,165
  • 9
  • 62
  • 113
1

Original PHP is a very trivial interpreter which does not perform any code generation. But there is an alternative implementation, a PHP to C++ compiler HipHop:

https://github.com/facebook/hiphop-php

SK-logic
  • 9,605
  • 1
  • 23
  • 35