PHP language specification?

2019-02-02 22:56发布

问题:

I know there is an official document for Java (JLS), I'd like to know if it's also the case of PHP language. I found the "Language Reference" section on the PHP manual, but it doesn't look as detailed as the JLS.

The thing is I have a good practical knowledge of PHP but I'm miserably clueless about what really happens under the hood.

If there isn't any official document, could you recommend me some good books to read?

回答1:

An initial draft specification for the PHP language has now been announced. The introduction of the specification reads as follows:

This specification is intended to provide a complete and concise definition of the syntax and semantics of the PHP language, suitable for use by the following:

  • Implementers of a PHP compiler
  • Implementers of a test suite for the PHP language
  • Programmers writing PHP code

For now, the runtime library has been excluded, as that is documented at www.php.net. As such, all forward references to library facilities have placeholders of the form (§xx).

See also the latest version of the draft.



回答2:

There was a discussion about that topic on the internals mailing list not too long ago.

You can check the status there.

Starting Post: http://marc.info/?l=php-internals&m=129379585417113&w=2

Dear internals

After enviously looking at pythons grammar (http://docs.python.org/dev/reference/grammar.html) I keep feeling that PHP is missing out on a lot of interesting meta projects by not having an official EBNF. [...]

and one hopefully helpfull follow up describing some grammar:

http://marc.info/?l=php-internals&m=129387252319019&w=2

And Stats take in the matter:

http://marc.info/?l=php-internals&m=129383062812273&w=2

Hi! [...]

You're not the only one thinking about it. But so far nobody moved from thinking about it to actually doing it :)

-- Stanislav Malyshev, Software Architect



回答3:

From what I read on Wikipedia, both PHP and Perl5 have in common that they are "languages" which are entirely defined through one single implementation. The language is precisely whatever the interpreter does. Neither are like C or C++ or Java or ECMAScript, which are standardised languages with many different implementations. (Apparently Perl6 will be different and actually have a specification. No idea of PHP will also one day make this step.)



回答4:

In this post, the HHVM Community announced a specification for PHP: http://hhvm.com/blog/5723/announcing-a-specification-for-php

It's now located in the following Github repo: https://github.com/php/php-langspec



回答5:

For the formally inclined, a detailed (executable) semantics of PHP is available at www.phpsemantics.org and will be presented tomorrow at the ECOOP 2014 conference in Sweden.



回答6:

From this (dated) weblog post it appears that there is no specification for PHP like there is one for Java.



回答7:

PHP and Java are different languages for different purposes, of course the documentation do not follow the same standard. I think php.net is the best place to find whatever you want, also have good books, it all depends what about your needs.

Java also has great books, and of course the Java Specification.

PHP does not have an specification, but have a tech manual of it and plenty of examples. What more do you need? Perhaps an specific book, try to look for Wiley Publishing they print books about PHP and other languages.