17 ms·
Announcing a specification for PHP
- LBarret 12y agoA language without a spec ? Damn, php is even worse than I thought. Still, FB may turn it (with hack and HMMV) into something interesting.
- masklinn 12y agoThat's not uncommon for implementation-defined languages. Ruby didn't have a language specification until the community set up rubyspec as it started getting serious about alternative implementations. Facebook is apparently getting serious about its own alternative implementation (or at least intending to be taken seriously) and are thus stepping in with a spec.
- ksec 12y agoOften I wonder if going without Spec is a good thing. Ruby doesn't want a Spec because Matz said Ruby is an always evolving languages. But the same could be said about HTML 5 where it does have a living spec.
- masklinn 12y agoPython has a spec[0] and Python is an always-evolving language as well[1], so I'll just go ahead and say that it's probably an excuse for laziness rather than an actual justification for not having a spec. [0] https://docs.python.org/2/reference/ https://docs.python.org/2/reference/ [1] https://docs.python.org/3/reference/ https://docs.python.org/3/reference/
- fnordsensei 12y agoWell, sometimes it's good to be able to tell whether some code is of the language in question or not. That's were a spec comes in handy, whether it's considered ongoing or not.
- dragonwriter 12y ago> Ruby doesn't want a Spec Both RubySpec and the ISO standardization effort suggest that this is less than true. > because Matz said Ruby is an always evolving languages. That's not a reason not to have a spec; that's a reason that the current bleeding-edge version might diverge intentionally from the spec and that the spec might trail. (Or, as in the case of HTML/HTML5, its why you might have both an evolving target spec, like WHATWG has with the HTML living spec, for language implementers to develop toward, and a more conservative one, like the W3C HTML5 spec, that is more geared toward what language users should target.) Without a spec -- preferably one that is or includes an executable test suite -- independent implementations are problematic, and multiple independent implementations that can experiment with different innovations is good for an "always evolving language".
- spacemanmatt 12y agoWhat's it been, 20 years?
- jaredmcateer 12y agoIf you read the article you would have known this. It is literally the first three sentences they cover this.
- baq 12y agosmartass, meet smartass.
- spacemanmatt 12y agoToo subtle, I guess. I was responding to the facts of the first sentence: More than twenty years without a spec. Why yes, that does remind me why I chose other languages.
- Aldo_MX 12y agoAs a discussion of any programming language grows longer, the probability of a bashing against such language approaches 1. Any similarity with Godwin's law is mere coincidence.
- krapp 12y agoThere are languages that everybody hates, and then there are the languages nobody uses.
- peterevans 12y agoThis is sadly true, on so, so many levels...
- superuser2 12y agoThere are languages whose communities everybody hates, but it doesn't seem to be that everybody hates Ruby or Clojure or whatever. Just that everybody hates their trendiness.
- spacemanmatt 12y agoI haven't found the Clojure haters yet but I can find a Ruby hater without looking too hard.
- dkarapetyan 12y agoCurious about the hate. As far as languages go Ruby is as coherent as it gets.
- lolpep8 12y agoAll the reflection and abuse of mixins are pretty worthy of hate.
- dkarapetyan 12y ago
- birkbork 12y agoThis is great news for the PHP community, and I for one applaud their effort. Contrary to what many HN hipsters seems to believe, PHP is quite a capable language, and HHVM / Hack is really pushing things forward. * Hack introduces type hinting, imo the major lacking part in PHP. * HHVM introduces speed to php. On a personal project calculating perlin noise, I got about 8x speedup on HHVM. * The specification helps pave the way for more implementations of PHP.
- TazeTSchnitzel 12y ago>Hack introduces type hinting, imo the major lacking part in PHP. Hack extends PHP's type hints, it doesn't add them. It also makes PHP statically typed.
- birkbork 12y agoI stand corrected. PHP does not have type hint for their internal datatypes (int, float, string). Only array is supported. Type hinting for your custom datatypes is supported, when used as function arguments. Also hack introduces type hint for function return type.
- TazeTSchnitzel 12y agoScalar (int, float, string) type hinting may be added in a future PHP version, and there's currently an RFC for return types (I expect it'll pass myself). PHP already let you type hint for classses.
- birkbork 12y agoCool! I wasn't aware of the RFC. Must be this one then? https://wiki.php.net/rfc/returntypehinting https://wiki.php.net/rfc/returntypehinting
- TazeTSchnitzel 12y agoYep.
- frik 12y agoThe PHP grammar in BNF starts at line 10354. It not that extensive as some may think and rather similar to what Java BNF looks like. The expression statement is a bit more extensive than in most languages, as PHP also supports the little known template-style (if elseif endif;): http://php.net/manual/en/control-structures.alternative-syntax.php http://php.net/manual/en/control-structures.alternative-synt... Thanks for the PHP spec. Btw. GitHub says "Sorry, this blob took too long to generate.": https://github.com/php/php-spec/blob/master/spec/php-spec-draft.md https://github.com/php/php-spec/blob/master/spec/php-spec-dr...
- arenaninja 12y agoI got the same message on GitHub. Did you checkout the repo in order to read it? Personally, this is exciting news, but I'm not sure that PHP is ready for this after 20 years. There's plenty of cleanup that needs to be done to userland naming conventions and parameter orders that in all likelihood won't get done anytime soon to avoid breaking BC
- frik 12y agoyes, you can also use the "Download Zip" button there: https://github.com/php/php-spec https://github.com/php/php-spec PHP ships with a lot of third party C libraries that are exposed in PHP with usually their original function names. Object orientation came with PHP 4 and later with PHP 5 the new better one (5.3+ with namespace support, traits, etc.). You can think of PHP as a mixture of C, C++ and Java for web development and CLI tools. I personally use all four languages, each one for specific purposes where the fit best. You can find function names like strstr in C, C++ and PHP (= indexOf in Java and JavaScript) - not a big deal.
- arenaninja 12y agoI'm at work so I was looking to peruse the proposal without downloading things. You can read it from PHP's git mirror: http://git.php.net/?p=php-langspec.git;a=blob_plain;f=spec/php-spec-draft.md;hb=HEAD http://git.php.net/?p=php-langspec.git;a=blob_plain;f=spec/p... I'm not sure that I would call PHP4 objects object oriented, as I remember it, it was all such a huge hack (down to being able to return null from a constructor). I only had to maintain some code like that at the tail end of PHP4's life, so I never found out whether that was how OOP was done in PHP4, or if it was a hack to simulate OOP in a language that didn't support it.
- juddlyon 12y agoCan someone explain to a layman why this is significant? I'm genuinely curious.
- oddevan 12y agoAs far as I know, this is providing a better answer to "How do we know this is valid PHP code?" Currently, the answer to that question is "Because it does/doesn't compile using the standard PHP interpreter." When this spec is finalized, the answer will change to "Because it does/doesn't follow the rules laid out in the PHP specification." In practice, there is a PHP spec, it's just an "unwritten" spec that is defined in the code of the PHP interpreter. With an official "written" spec, it will open the door to alternative PHP interpreters (like HHVM), since they will be able to say that they also support "PHP" as defined in the spec. Hope this helps!
- ionforce 12y agoHoping to tide you over until a better answer comes along... Generally when complex programs (like an entire programming language) are made, there is usually a "specification" of its behaviors. This way, you can communicate to people, hey, my program does ABC and does NOT do XYZ. Also, it helps you delineate between bugs and what not. My program does AB DEF. Is that a bug? Or a feature? What does the specification say? Not all programs have a specification. It's a bit formal and unnecessary. Except in a specific scenario where you have multiple/competing implementations of the same programming language. Now that there are multiple players, we need to know exactly which behaviors are per the spec and which behaviors are per the implementation. All coffee makers must make ABC XYZ. This is the spec. Sony CoffeeMate makes ABC DEF XYZ. It matches the spec and throws in some extra features. Samsung Coffee Xtreme makes ABC PQR XY. This also throws in extra features but is actually missing one from the spec. TL;DR it helps a language evolve independently of its implementations (come the day that a language != its implementation)
- nawitus 12y agoAnother way to answer this question is that a programming language specification tells what the language does in the case there's no stack overflow answer for the question.
- deleted 12y ago[deleted]
- maaaats 12y agoAfter recently having to work with modern PHP, I have to say a lot of the criticism of the language is unfounded. It's changed a lot since I first used it. But the stdlib is still hard to manage. Different naming conventions, different order on the parameters for functions that do almost the same thing, and every function is global. Couldn't they keep all that for backwards compatibility, but create more sane wrappers and include them as part of the stdlib? For starters, group them by what they work on (arrays, strings, numbers etc.) as static functions on some relevant class ( String::str_replace(...) ), and later have more methods one can call on the objects themselves ( myStr.replace(...) ). Is this being worked on? Can this spec help with that?
- birkbork 12y agoIf you want to order your program in a specific way, you introduce the appropriate level of abstraction. Same as with any other language. EDIT: i totally agree that the standard functions are a complete mess in PHP. But they have to stay around for backwards compatibility. Have a look at the SPL classes: http://php.net/manual/en/book.spl-types.php http://php.net/manual/en/book.spl-types.php
- flatline 12y agoWhen you're talking about the core libraries that ship with the language, it seems unreasonable for every PHP developer to have to introduce it themselves.
- cdmckay 12y agoThis simply isn't possible in a way that would be convenient. For example, how would I make a string abstraction? Create a class? Ok, so we have: $str = new String("foo") $str->replace(...) over $str = "foo" str_replace($str, ...) This is fine, if we ignore the fact it's much slower. Where it really gets annoying is PHP's lack of operator overloading. That means to concatenate I'd need to do $str->concat($str2)->concat(new String(" "))->concat($str3) instead of $str . $str2 . " " . $str3 There's things you can do to make the API a little bit more convenient (i.e. allow it accept PHP strings, etc.), but ultimately it becomes a huge pain, especially if you want to start interoperating with other libraries that are using a different abstraction or, more likely, using the regular PHP types and functions.
- robert_nsu 12y agoThis is good and long overdue. I disagree with the claim of it being the lingua franca of the internet though.
- joshdance 12y agoRookie question, but what does a language specification for PHP do or mean? I assume this is good, but don't know why. :)
- x0x0 12y agoThe obvious thing it does is lays the groundwork for multiple first-class implementations. As it stands, the program php essentially is the reference: whatever it does, implementation quirks, bugs, and all, is what php should do.
- Dewie 12y agoWhat is a language, really? It's not really an implementation (necessarily); a language can have multiple implementations, in which you have to ask "which one is the language?" if they have subtly different behaviour. In order to enforce what a language is, you can introduce a specification. This will say that "given a program X, the language will behave like Y". Now any implementation of the language can be checked for conformance. The spec itself might be some document, or perhaps just a "blessed" implementation ("the implementation is the spec").
- ecaron 12y agoI sure hope Sara Golemon gets the recognition out of this that she deserves (and which the article starts to build.) Having met her at a couple conferences, she continues to demonstrate a brilliant understanding of what it takes to build a programming language WHILE being a tremendous advocate and builder of a community where being a member isn't always... popular. Rock on, @saramg
- SaraMG 12y ago<3 The props go to Joel Marcey, Drew Paroski, and Rex Jaeschke though.
- dancecodes 12y agoWho needs in this: php or hhvm? Many years the language grow without spec and no way? Strong spec its good but users needs with other... Its more features and clean internal API without tainting something like...you know...
- cottonseed 12y agoAt first I thought they were announcing a formal specification for PHP. Who's going to win the race to build the first formally verified blogging platform?
- danso 12y agoMaybe I'm missing something here...but the OP links to what must be a gigantic Markdown file that Github will not serve up...Is the spec meant to be in a giant doc, or will it be split up into smaller sections? This seems like a perfect use for Jekyll if they're going to publish on Github... In any case, I did a quick-fork and generated a Github page from the Markdown file linked to by OP: http://dannguyen.github.io/php-spec/ http://dannguyen.github.io/php-spec/
- jimarcey 12y agoNice. Thanks. In my mind, there will be multiple renderings of the spec (like what you had done here). I have plans to split the spec into multiple, smaller .md files based on topic. The gating factor was managing the internal reference links, but I can work around that with some tooling. I did not want this to hold up getting the spec out there though.
- lnanek2 12y agoI'm not really a fan of having a second source of truth compared to in depth material already on php.net. The two will invariably start to disagree and php.net is much, much better than any spec or documentation I have ever read. Using Android is a nightmare compared to php.net because every single thing on php.net has extensive user generated documentation whereas Android is just some broken official docs. I submitted a bug report with a fix for the Android docs telling people to make dialogs in a way that simply crashed and didn't work and it was never merged in for years and years. So official specs tend to suck.
- Zelphyr 12y agoI think a spec benefits language implementors more than it does every-day users. Sure, it will influence things in every-day PHP programming but ultimately I think the target audience is different. Think of it as what the ECMA spec is to the Node.js API docs. Rarely does a user writing JS code using Node need to reference the ECMA spec (though they should by all means be familiar with it!) but they almost certainly have the API docs bookmarked.
- krallja 12y agoThe ECMAScript spec might be a bad example, simply because Annotated ES5 is so good. http://es5.github.io/ http://es5.github.io/
- mehrdada 12y ago> PHP is definitely the lingua-franca of the internet. Definitely wrong. If there's a lingua-franca of the internet, it's JavaScript.
- jacquesm 12y agoThe internet does not have a lingua franca. The web does, and it is HTML.
- Pacabel 12y agoSorry, that's total nonsense. Far more of the Internet depends on C, C++, or some mix of the two. Software written in them runs the networking gear, the servers, and the clients that are critical to the Internet's existence. And keep in mind that the major JavaScript implementations today are all built using C and/or C++ in one way or another. So pretty much anywhere that JavaScript is being used, then C and C++ are being used, too.
- TazeTSchnitzel 12y agoJS is the lingua franca of the browser, but PHP is the lingua franca of the server side.
- deleted 12y ago[deleted]
- ChikkaChiChi 12y agoPHP is fantastic if you are starting from scratch and you don't necessarily need any third party libraries. PDO is very well done and the native database drivers are some of the fastest available. With a properly tuned nginx/fpm/apc stack, I've been able to deliver solutions that truly back up the results you see from comparison benchmarks like Techempower. In many cases in web development, PHP can be the right tool for the job!
- girvo 12y agoWith HHVM + nginx you can really fly! Seriously, it's amazing how fast it is (and the Techempower benchmarks put it at #1 for anything with multiple requests and data handling!)
- frik 12y agoYou are spot on, Nginx+HHVM is really fast. I am an early adopter of HHVM (since Dez 2012) and it really shines on sites with thousends of requests per seconds. I heard PHP 5.5+ on Nginx (FPM) is fast as well. And I prefer PHP as I can code websites without the need of frameworks (PHP is "the framework") with a C/C++ like syntax. The idea of libraries is much older than frameworks, and in the end libraries are so much more flexible IMHO.
- tomschlick 12y ago> And I prefer PHP as I can code websites without the need of frameworks That either means A) you re-invent the wheel every time you start a project or B) you have your own implementation of commonly used items (your own framework) I personally would rather have a framework vetted & maintained by thousands of other developers than one I put together myself.
- chriswarbo 12y agoTo be fair, PHP's stdlib is essentially a Web framework. It comes with $_SERVER, $_GET, $_POST, header(), etc. built in, which other languages (Python, Haskell, Perl, etc.) would define in a framework. Hence there's no need to redefine stuff over and over. Hell, PHP is even a templating language by default, thanks to its <?php ?> tags. Of course, this doesn't answer the related questions: is PHP's built-in framework any good? Is it a good idea to include a Web framework in all scripts (even non-Web ones)? Is it a good idea to write all application logic inside giant <?php ?> tags in template files?
- rafekett 12y agofantastic work that's long overdue. any commitment from the zend team to implement it? if not it's a specification for HHVM, not PHP.
- kayoone 12y agoRecently i feel there even is a kind of PHP renaissance. I think its a good time to revisit PHP and look at what it has to offer these days. The community is enormous and open source frameworks like symfony2, zend2 or laravel are thriving like never before with solid implementations for nearly everything. With composer there is mature packet management now and in general the code put out for these kind of projects is of very high quality. And then there is facebook pushing PHP forward with things like HHVM, however for most stuff i have worked on, php execution time hasn't really been the bottleneck anyway, but its nice being able to squeeze out even more speed. These days i also work a lot in node and angular, but PHP (using symfony) is still my goto language for a solid REST backend and/or classic static content based websites.
- kangax 12y agoLooks like PHP spec is about twice smaller than ECMAScript 5.1 (http://es5.github.io/ http://es5.github.io/) ~42K vs ~82K words.
- TazeTSchnitzel 12y agoThe ES5 spec specifies its whole standard library, however ;)
- ck2 12y agoFacebook first needs to bring HHVM up to full compatibility before they try altering the spec. I also discovered Facebook makes all their "contributors" (anyone who does a pull request) sign an agreement with them, which seems weird and not cool. https://code.facebook.com/cla https://code.facebook.com/cla
- skymt 12y agoIt's not unprecedented. GNU projects require contributors to sign over the copyright for their code. Facebook's requirement of copyright and patent license is relatively restrained.
- dragonwriter 12y ago> Facebook first needs to bring HHVM up to full compatibility before they try altering the spec. Defining a spec (there isn't a pre-existing spec that is being "altered") is an important part of moving to acheive compatibility, since its how you know what the target is. HHVM spawning a spec effort for PHP is a lot like Rubinius spawning RubySpec.
- spicyj 12y ago> I also discovered Facebook makes all their "contributors" (anyone who does a pull request) sign an agreement with them, which seems weird and not cool. https://code.facebook.com/cla https://code.facebook.com/cla This is standard for virtually any open-source project backed by a large company and for many that are independent (e.g., all Apache projects: http://www.apache.org/dev/new-committers-guide.html#cla http://www.apache.org/dev/new-committers-guide.html#cla).
- madeofpalk 12y agoThese CLA are fairly common arent they, esp. among largercompanies that have/run open source projects? ? e.g. https://github.com/angular/angular.js/blob/master/CONTRIBUTING.md https://github.com/angular/angular.js/blob/master/CONTRIBUTI...
- vithlani 12y agoHahahah.... what a waste of time and resource. FB would rather direct their resources towards this meaningless crap then run the risk of their top employees getting bored -- and leaving them.
- xanth 12y agoJavascript is the lingua-franca of the internet not PHP.
- k3liutZu 12y ago> PHP is definitely the lingua-franca of the internet. I think they misspelled Javascript.
- TazeTSchnitzel 12y agoPHP is on the server.
- xutopia 12y agoA lot of the sites we frequent have python, ruby or C# on the server.
- TazeTSchnitzel 12y agoThat's not the point. PHP is the lingua franca of the server-side as it's by far the most commonly used language and widely understood. Do others exist? Sure. Just as other languages exist. But PHP's the big one.
- ZeroGravitas 12y agoThis should help the PHP-NG project too. I was a bit worried to see they were doing large refactorings to increase speed when the PHP test suite only has about 30% code coverage.
- fabriceleal 12y agoThis is great news, now we just need to lobby for the creation of this specification in machine readable files, using something like the K Framework, instead of using the usual wall of text. http://www.kframework.org/index.php/Main_Page http://www.kframework.org/index.php/Main_Page
- SimeVidas 12y ago“PHP is definitely the lingua-franca of the internet.” Uhm, no.
- stefantalpalaru 12y agoBetter late than Python.
- pbiggar 12y agoIt took a while, but I read the spec and wrote a critique: http://blog.circleci.com/critiquing-facebooks-new-php-spec/ http://blog.circleci.com/critiquing-facebooks-new-php-spec/ (comments at https://news.ycombinator.com/item?id=8114919 https://news.ycombinator.com/item?id=8114919)