PHP Gets A Formal Specification
Written by Ian Elliot   
Thursday, 31 July 2014

Given how important PHP is in terms of its use, it is very surprising to learn that it only now is getting a formal specification after 20 years of use. 

phplogo

Languages come about in one of two ways. Either an academic sits down and constructs a language, complete with grammar and formal specification, or an enthusiastic programmer just implements what is needed.

In the case of PHP it was an ad hoc language designed to make building web pages easier. As a result it is a bit of a mess and the fact that it has evolved as it has grown in complexity hasn't helped. The specification of the language was essentially its current implementation and the documentation on how to use it. 

Now a group led by Facebook has created a draft specification which is available on GitHub. The definition includes both syntax and semantics. The group is led by Facebook because the company uses PHP extensively and needs it to be a language capable of logical evolution hence the interest in a formal spec. The group also consists of Rasmus Lerndorf, the man who invented the language in the first place and Andi Gutmans, CEO of Zend the PHP tools vendor. 

The specification is in easy to read form. For example;


 

Compound Statements

Syntax

  compound-statement:
    {   statement-listopt  }
  statement-list:
    statement
    statement-list   statement

statement is defined in ยงยง.

Semantics

compound statement allows a group of zero of more statements to be treated syntactically as a single statement. A compound statement is often referred to as a block.

Examples

if (condition)
{ // braces are needed as the true 
// path has more than one statement // statement-1 // statement-2 } else { // braces are optional as the false
// path has only one statement // statement-3 } // ----------------------------------------- while (condition) { // the empty block is equivalent
// to a null statement }

 

 


 

This is clear enough to make it suitable for checking up that you have understood the more informal documentation. There is, of course, the issue of how accurately it reflects the real world of the implementation. If you find a discrepancy at the moment it is the specification that will have to change. In the future the spec could be in charge of what the implementation should do. 

With the next major version of PHP settled as version 7, and with work on improving the speed of the language in the form of Facebook's HHVM and PHPng, having a fixed reference specification is very necessary for us to know when something deviates from the standard.

phplogo

Banner


Introducing Mozilla Rec Room
27/08/2014

If you are wondering what tools to use to build a client side web app, Mozilla's new Rec Room has a set of recommendations and a tool that attempts to integrate them for you. This is described as "wor [ ... ]



Time To Enter The Intel RealSense App Challenge
22/09/2014

With just days to go until October 1st, there is still time to come up with an idea for using the new Intel RealSense technology that could win you $50,000.


More News

blog comments powered by Disqus

 

Last Updated ( Friday, 01 August 2014 )
 
 

   
RSS feed of news items only
I Programmer News
Copyright © 2014 i-programmer.info. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.