20 ms·
New in PHP 8
- mharroun 7y agoHonestly php seems like the common cold... an annoyance that is everywhere and treated with little seriousness. However every evolution it gets better and stronger and adapts other learnings from other languages. It really shouldnt be treated as a joke any more. Ps: I love php and jquery... not for any real saas systems but no other tool set allows me to spin up and prototype full web app prototypes in sub 90 min. As a senior tech manager php and Jquery allow me to show functional prototypes quickly and easily get buy in from other department stake holders.
- irrational 7y agoOne of the biggest complaints I've read about PHP is that many things are not consistently named (having never used PHP, I might be wrong). If this is true, are there any plans to fix this?
- duncan-donuts 7y agoIt is true and no I don’t think there’s much talk of changing it. There’s also a problem with inconsistent method arguments. Just look at array_map[1] and array_reduce[2]. This is just the one example that bit me the most, but there are other inconsistencies like this all over the language that require you to constantly look things up. [1] https://www.php.net/manual/en/function.array-map https://www.php.net/manual/en/function.array-map [2] https://www.php.net/manual/en/function.array-reduce https://www.php.net/manual/en/function.array-reduce
- nkozyra 7y agoI remember reading a cogent explanation for this inconsistency but can't seem to locate it. JavaScript suffers from inconsistent mutation/return of array values in array functions, too. PHPs design problems are mostly being swept away; it's the legacy that keeps its reputation down.
- aspratley 7y agoRasmus Lerdorf has talked about it in other videos but this is one https://youtu.be/iGOAQli7tGc?t=1485 https://youtu.be/iGOAQli7tGc?t=1485 Basically, groups of functions are consistent: string,array etc. Their parameter order was usually based on whatever the underlying C API was.
- cdirkx 7y agoI just encountered this last week. I had to explain to my fellow non-IT students why I was making loud gasps of confusion.
- Moru 7y agoI use an editor that has the php help built in to not get confusing errors. You type the beginning of the command and it directly tells you what part is the needle and what is the haystack.
- dana321 7y agoArray map takes one or more arrays with a callback, so the arrays have to be on the end. Array reduce has one array as a parameter, as does most of the other functions and they all have the array as the first parameter. Its only one function, and its an inconsistency for a reason. Lets not blow it all out of proportion.
- conradfr 7y agoIn practice it hasn't been a problem for me in a long time (I've been doing PHP since PHP3 so I have some perspective on it). First the documentation is fine and easily accessible, second your IDE will hint you the correct order and finally in a real world web framework situation you don't even use those functions that much anyway. My biggest complaint would in fact be the concurrency situation, it's still not easy and relies on external libraries that feel half-hacks. I guess Elixir spoiled me in that regard.
- tpetry 7y agoAnd when enabling strict types you will get an error anyway if you have the wrong order because the types will not match.
- akie 7y ago"My biggest complaint about this language I've never used is something I'm not sure is true. Is it?"
- irrational 7y agoWell, I have worked as a web developer for 20+ years. I've heard that PHP is inconsistent dozens, perhaps hundreds of times. I've just never verified it myself since I've never used PHP.
- haolez 7y agoMaybe the Hack language?
- monoideism 7y ago> As a senior tech manager php and Jquery allow me to show functional prototypes quickly and easily get buy in from other department stake holders I totally get it if you prefer to leverage your knowledge of jQuery, but modern JavaScript is just as quick to use. Eg, `fetch`, `querySelector`, and many more. Combined with modern css with flexbox and grid, and prototyping becomes very quick.
- kyriakos 7y agoI think the comparison is not between jquery and native Dom functions but between making something quickly with jquery compared to using angular or react for example
- monoideism 7y ago> I think the comparison is not between jquery and native Dom functions but between making something quickly with jquery compared to using angular or react for example Probably. I was just making the point that jQuery is no longer needed for most use cases. Lots of folks have no idea what the latest browsers are now capable of.
- mharroun 7y agoI'll admit as I moved into managmemt js has also improved. These prototypes are tossaways so it's just faster for me.to grab jquert. (Btw I love react and use it in any serious project... but each to definitely has its place)
- te_chris 7y agoModern JS is a total shit show of competing build tools, APIs that only work in certain ways in certain places, NIH reinventing the wheel. Thankfully there's some standardisation now, mostly due to the heft of Facebook, but it's still some much more work than it needs to be, espeically on the server compared to other web stacks like Elixir Phoenix, Rails, Flask, even Laravel (despite it's frustrating APIs).
- krsdcbl 7y agoIt never should have, the treatment php gets mostly feels like people finding it "not cool enough", seldomly I've seen someone have a real reason to avoid it
- Beldin 7y agoMy pet peeve: http://phpsadness.com/sad/47 http://phpsadness.com/sad/47 TLDR: checking passwords in php used to rely on using the correct comparison operator. Using the'==' operator would introduce subtle flaws. Using '===', you're fine.
- tudorw 7y agoThat's in the instructions.
- dvdkon 7y agoHaving to read those to see if a working program is fully correct is a failure on the language's part.
- jorams 7y agoDocumented insanity is still insanity. A very clear example that was luckily removed quite quickly: php_check_syntax.[1] > Check the PHP syntax of (and execute) the specified file This function's name and its documentation suggest completely different use-cases. In fact, it apparently does the one thing I wouldn't expect it to do based on the name. It's insane, and it cannot be excused just because the insanity is documented. The example given by GP is a lot more subtle, but this is not a good argument to make. [1]: https://www.php.net/manual/en/function.php-check-syntax.php https://www.php.net/manual/en/function.php-check-syntax.php
- tudorw 7y agoI accept that, but I still don't really understand the issue, which programming language can I pick where I don't need to read about what does what, I don't feel any language is intuitive per se?
- elric 7y agoPHP hasn't been a joke since PHP 4, when it pretty much supplanted Perl, which until then had been the dominant scripting language for the web. Its deceptive simplicity has been both its strongest and weakest point. On the one hand, it helped draw hordes of young developers into the field. On the other hand, it gave a lot of programming power to a bunch of people with very little programming experience, leading to the image of a buggy joke of a language. I don't think who has had a serious look at PHP would call it a joke these days.
- pjmlp 7y agoPHP 5 was what made me make peace with PHP.
- piinbinary 7y agoGiven how much PHP is used, having a JIT will probably save a meaningful amount of electricity
- agumonkey 7y agoI'm not sure if I'm inventing things but I think there was a report when facebook introduced hiphop compiler.
- tpetry 7y agoYes hiphop compiler was very fast when they started but shortly after normal php was faster than the hiphop compiler. So the hiphop compiler transformed into hhvm which was php with some really nice additions. But at some point the language inventions got more and more in conflict with the increments in the php language so they dropped php support and its now only using its own language which is a very improved version of php
- deleted 7y ago[deleted]
- blibble 7y agothat page seems to state that it only works in the context of a single request unless you've got CPU bound PHP code... it seems like a complete waste of effort
- kyriakos 7y agoIt's a way to promote php for other type of applications. Check swoole and reactphp, they will be benefiting the most.
- deleted 7y ago[deleted]
- softwarelimits 7y agoAlso check for memory leaks while you are at it.
- chx 7y ago> Undefined variable: Error exception instead of notice Well, this is where the chaff separates from the wheat. There's no small amount of crappy code out there which will WSOD after this. Or actually print the exception because they couldn't even bother to switch display errors on... Of course, no even remotely sane codebase will be affected, but... Make no mistake, this is a good change but it will cause some teeth gnashing.
- codetrotter 7y agoOver time I think (hope) this sort of change will help to improve the code that people write. But I will not be surprised to see some people say things like “PHP 8 broke my code”. Of course, what those people might not realize is that PHP 8 did not break their code, the code was always broken, and PHP 8 is now going to surface the brokenness of that code. But even with code that people refuse to fix, this sort of change will make the brokenness of that code more apparent to others, and so the number of people that use that broken code will cease to grow. If not entirely, then at least reduce in pace of growth. That is good for the ecosystem of computing. As a proponent of correctness in computing, this makes me happy :) We all write bugs, but everything our tools and languages of choice can do to help us reduce the number of bugs and the severity (impact on security) of our bugs, the better.
- userbinator 7y agoI think it's really a philosophical question what is "broken". An undefined variable used to have a particular and also well-defined behaviour, now it has a different behaviour. Personally, I think a lot of these design decisions which some people abhor is why PHP became popular in the first place. In that perspective, turning it into yet another "big bureaucratic language" is very much against the spirit of its existence.
- koolba 7y agoSince the dawn of programming there’s been a schism as to whether undefined means empty versus being a logical error. But deep down we all know what it should mean.
- CraftThatBlock 7y agoI'm a bit confused. I thought PHP 7 introduced a JIT, hence why it was much faster (in some cases ~5x faster). How is it different from the PHP 8 JIT? I always assumed that HHVM is what brought JITs to PHP originally, followed by PHP itself.
- jonny383 7y agoI believe there were attempts at implementing JIT in PHP 7 which were unsuccessful against the timeline for release. Instead, they did other optimizations and managed to squeeze quite a bit of performance doing this (comparable to HHVM).
- nkozyra 7y agoI think 7.1 or 7.2 was where it generally beat HHVM.
- CiPHPerCoder 7y agoPHP 7 didn't introduce a JIT. There was an experiment in the 7.x series, but it never surfaced.
- lowercased 7y agoat least some of the speed bump in 7 came from reduced memory usage. IIRC, array pointer size was reduced significantly - something like 120+ bytes per array entry was reduced to ~40 bytes, so far less memory needed to be allocated and managed throughout an execution cycle. I'm sure there were other reasons for speed boosts, but that is one that's stuck in my head for some time.
- rnijveld 7y agoPHP 7.0 was mainly faster because the internal variable data structure (zval) was redefined such that PHP doesn't need to follow so many layers of indirection and doesn't need a full ref-counted heap allocated data structure for every int and bool in your script.
- jonny383 7y agoUnion types look somewhat handy, especially if you're using T|null In PHP 7, you can still do function foo(string $bar = null): void Which is a little clunky...
- EspadaV9 7y agoIn PHP 7 the correct code should be function foo(?string $bar): void Having `= null` marks the parameter as optional with the default being `null`. Using `?string` means there is no default and you can pass in either a string or null.
- jonny383 7y agoYes thanks. A little rusty on the old PHP knowledge off the top of my head.
- vgaldikas 7y agoYou should have '?' string
- flir 7y agoI'd rather have overloaded function signatures, to be honest. function add(string $a, string$b){} function add(int $a, int $b){}
- no_wizard 7y agoI like that 8 has some great changes coming and the JIT will be a long term win. I just hope the core maintainers evaluate true async/await constructs for PHP. I also hope that the JIT leads to more significant advancement in PHP and how it manages memory. For all it’s improvements it’s still really prone to memory leaks easily
- omnimus 7y agoPHP is synchronous (if you dont add async extensions). How would you use async await in the language?
- no_wizard 7y agoreactphp already fakes this with Promises, much the same as JavaScript Promises. Why not make this a genuine language construct. You can even use the async and await “sugar”. Coroutines would also be a genuine improvement
- pbowyer 7y agoIf this is something you would like to see in PHP, please have your say on the mailing list. There are some discussions, most recently https://externals.io/message/108226 https://externals.io/message/108226
- omnimus 7y agoSure there is also most notably swoole if you want async i would go all in. That said it is going to be so wierd for most php programmers you might aswell hire nodejs people and do it in node where language and ecosystem is all about async.
- no_wizard 7y agoMaybe, maybe not. The nice thing about adding constructs to a language is that you often can opt in when you do use them. Also, if you have PHP developers, its going to take less time for them to learn async constructs in a language they're familiar with than switching your entire backend to nodejs just to leverage those features. Seems to me like that'd be far more work and cost a lot more. Its not trivial to just upend an entire system.
- ksec 7y agoAt these rate of improvement, along with Laravel, may be I should seriously evaluate moving back to PHP stack. It was only the other day Antirez, author of Redis [1] was complaining the Ruby Stack is more complicated than it should be. And I wholeheartedly agree. [1] https://mobile.twitter.com/antirez/status/1223286005219774464 https://mobile.twitter.com/antirez/status/122328600521977446...
- deleted 7y ago[deleted]
- core-questions 7y agoThere was never anything wrong with PHP, really. * If you wanted to scale it horizontally, it was ready to do that 15+ years ago * No problem running it completely stateless * Deploys are completely sane and predictable, it's just a bunch of files, and even when composer came along it didn't really change that too much * Performant enough as far as the interpreted web languages go * No problem writing a RESTful backend in it and fronting completely "modern" client facing tech on the top if you want * Server side rendering since day 1 Like, it came down to people complaining about some function names / param orders as if it were the end of the world. I think a certain subset of people (shall we call them hipsters?) are just keen on finding new ground where they can rewrite the same boring things instead of working hard to improve the ecosystem of something existing. I moved on from PHP aeons ago because it got this undeserved bad rap, but I still follow it and would welcome the chance to run it again.
- enraged_camel 7y ago>> There was never anything wrong with PHP, really. I mean, your listed points are arguably correct, but this sentence is quite incorrect. edit: downvoted by PHP fans. It's OK, I get it, nobody likes it when others dunk on their favorite language. :)
- wk_end 7y agoYou were downvoted because your post lacked any real content or rebuttal (and, probably, for the edit - no one likes it when people complain about downvotes). FWIW though, you're absolutely right - there was (maybe still is?) an enormous amount wrong with PHP. The only real rebuttal core-questions needs is a link to the classic essay, "PHP: a fractal of bad design" [1], which lists far, far more problems than just issues with function names or parameter order, and does it more comprehensively and with more style than you or I could hope to. [1] https://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/ https://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/
- AnimalMuppet 7y agoMisread that as "new in PDP 8". I was expecting an old-school DEC story for a moment...
- abbiya 7y agowhy does php garbage collect anything when there is a reference ? (weakmaps)
- detaro 7y agoIt doesn't, unless you specifically tell it that it should ignore a reference by using a weakref or weakmap.
- function_seven 7y agoRight now, it doesn't. If there's a reference, then the item is not garbage collected. The WeakMaps change will allow a developer to take a reference to something but say, "Hey, I'm caching this for now, but if you need the space, I'm not married to it."
- cdubzzz 7y ago> The @ operator no longer silences fatal errors Interesting. There are still some legitimate (well, “legitimate”) use cases for that behavior e.g. with PHP’s native XML extensions.
- treve 7y agoAre you sure those are _fatal_ errors?
- scandinavian 7y agohttps://3v4l.org/saHj2 https://3v4l.org/saHj2 However you could just catch Exception. Not sure why a parse error is a "Fatal error".
- gnud 7y agoA PHP parse error (of your code) is a fatal error. A xml parsing error in the SimpleXmlElement constructor is not a fatal error - it throws an exception. An uncaught exception is a fatal error.
- marcrosoft 7y agoPHP is looking a lot like Java these days.
- celticmusic 7y agoI've seen a lot of people say this but I don't understand the sentiment, could you explain it?
- takeda 7y agoEither you haven't used Java, or didn't look at the examples in the link. The code looks similar to Java code, how classes are constructed, extra type modifiers, type access levels etc.
- celticmusic 7y agoOr I'm surprised at the notion that types in an OO language is the minimum bar for "turning into Java"? That seems like a nonsensical litmus test.
- takeda 7y agoOther languages that have these but they do look different. I personally don't see anything wrong with it, but it does resemble Java to me.
- gcpwnd 7y agoThe OO model is superficially adapted from Java. The open source community is pretty much following the SOLID / clean code cult. There are of course huge differences but the community acts like we're building a second java and there is no scepticism about it.
- romanovcode 7y agoLanguage either dies a hip cool thing or lives long enough to become Java
- mekster 7y agoI wish PHP makes the end of line semicolons optional like other modern languages. It saves a lot of typing when I have to trace brackets after auto completion to add the semicolon instead moving to the next line.
- giornogiovanna 7y agoIn JavaScript the automatic semicolon insertion is almost universally reviled. Why not just have your editor insert the semicolons for you if it's such a pain to type them?
- BurnGpuBurn 7y agoI never use semicolons in js except in for loops like for(let i=0; i<100; i++) In all other places it isn't necessary anymore.
- mekster 7y ago> Why not just have your editor insert the semicolons for you. They don't insert the semicolons automatically as it can't tell if it's the end of line or I'm about to invoke a chained method etc. Not sure what the down votes are about as it literally increases 2 to 3 letters of extra typing just to append the semicolon after auto completion. > In JavaScript the automatic semicolon insertion is almost universally reviled. Why? There's literally no need except on a rare occasion. My IDE happily gets rid of JS semicolons and it's far easier to type. Ruby and Python don't need one. Just feels tedious compared to other scripting languages.
- fraktl 7y agoErm.. no. It's the opposite for me. I've used semicolons for over 2 decades. I can type pretty fast. Removing one character under the guise of "but I type faster" is just pure BS. Without semicolons, I can't work. The person who came with the idea to remove semicolons in JS earned a special place in hell.
- Annatar 7y agoI expect to have some time soon and I'm planning on writing a full-blown application in PHP, using nothing but functional style programming. Should be fun.
- timvdalen 7y agoIt should! Have a look at Illuminate\Support\Collection, which you can pull in as a separate package (apart from Laravel). It makes doing functional stuff in PHP a lot of fun.
- mpetrovich 7y agoYou might also be interested in Dash: https://github.com/mpetrovich/dash https://github.com/mpetrovich/dash
- Annatar 7y agoNO FRAMEWORKS!!!
- Annatar 7y agoNO FRAMEWORKS!!!
- esistgut 7y agoEvery time I see an article about new features in PHP I search the page for the "annotation" keyword. To be honest I find it a little bit puzzling that to this day a large part of the ecosystem (Symfony, Doctrine, API Platform) revolves around docblock annotations.
- fraktl 7y agoAgreed. Personally, I hate annotations. This is the reason why I never bothered with any tool in PHP ecosystem that relies on annotations. It looks ugly, it feels ugly, it doesn't fit with my mental model - I avoid it entirely.
- flir 7y agoAgree so strongly. Executable comments. Whose bright idea was that?
- move-on-by 7y agoI love annotations - but only at a language level. Annotations being hacked in through comments is a dirty and I do not like it.
- rawfan 7y agoMaybe check out Laravel. They banned all annotations from the framework. Best decision ever.
- larzang 7y agoEverything in the Symfony/Doctrine ecosystem that uses annotations does so as an option for those who prefer them. If you don't like them, you can usually just as easily use YAML or XML or PHP configuration. Most developers seem to like them (brevity, locational grouping of concerns), so they tend to get treated as a default, but they're not the only option or the only one treated as a first-class choice. Like much of new-PHP, this also seems to be something largely borrowed from the Java world, it's hardly something new or invented by PHP.
- 7y ago
- fraktl 7y agoJudging by comments I saw and what I had my own clients tell me over the phone/mail, it would appear that there's stigma associated with PHP, mostly due to one super-popular blog post called "PHP - a fractal of bad design". I won't go into rebuttal here, the author of the post did enough damage as it is. PHP evolved significantly since version 4. Version 5 was the "big" deal, with good object oriented features. Version 7 brought the performance in, so we could get rid of Facebook's crappy HHVM (thank you PHP team). Version 8 brings JIT, however most of the workload isn't CPU bound but I/O bound. So, here's something for PHP devs: Swoole. http://www.swoole.co.uk http://www.swoole.co.uk -> this is an extension for PHP which brings in the same primitives available to people using Node.js or Golang - coroutines, async I/O, channels, event loop control and much more. What it essentially does is turn ALL I/O from synchronous to asynchronous. Without any code change or control structure in form of async/await or promises. Write synchronous code, get asynchronous performance. From my own experience (I've been running swoole in production for 18 months), the performance gain I saw was minimum 500% to a maximum of 2000% (the numbers aren't a joke). As for PHP - it's a programming language. You can use it right or you can use it badly. This rule applies to almost any language. There's no language in this universe that can turn a bad programmer into semi-ok programmer or even good programmer. If you haven't got the habits and knowledge, there's no language that can rectify it. I've seen way too many people thinking the language of their choice is to blame, but it was always the person in the chair. PHP performs well. Ecosystem is quite large and luckily there aren't competing standards. Composer, the package manager, is wonderful. There's plenty of frameworks to choose - for web and for CLI usage. Features are being added, slowly but steadily. I use PHP with Laravel + nginx, next to Nuxt + Vuetify + TypeScript for frontend stuff. Personally, I really like how the mentioned tech can be utilized to create great apps fast - with structured code, that look good and work quick. Edit: one of the best and most powerful features in PHP (starting with 7.4) is the FFI - foreign function interface. The option to utilize libraries or entire software, without the need to write PHP extensions, is what's amazing for me (I also need it due to nature of my work). PHP is way more powerful than people give it credit for. But I guess that's what happens when opinions are formed by looking at titles and number of "likes" or other meaningless numbers designed to mislead.
- dana321 7y ago
- bufferoverflow 7y agoPHP is already one of the fastest languages. Hopefully JIT will make it even faster. Currently it places #11 on the famous framework benchmark: https://www.techempower.com/benchmarks/#section=data-r18&hw=ph&test=db https://www.techempower.com/benchmarks/#section=data-r18&hw=...
- wopian 7y agoIs there a key for the different language colours? I figure PHP is blue because of Swoole, but the rest are just a sea of colours I have to Google the web framework of to find the language (on mobile at least).
- smarnach 7y agoThere's a column called "Lng" that shows an abbreviation of the language.
- paulintrognon 7y agoI don't really understand that benchmark. How can swoole (#11), written in PHP, be faster than PHP itself (#125)?
- oaiey 7y agoBecause Swoole is a framework with an independent HTTP server and mysql driver. If you get rid of this two, it is just the algorithmic power of the runtime of PHP which factors in here. swoole is co-routine based, having a much better lifecycle and resource sharing as a consequence. Which leads to much more throughput.
- fraktl 7y agoSwoole hijacks network I/O from Zend Engine. Thus, it's capable of performing async I/O while keeping the userland code the same. What the benchmark shows is what happens when there's non-blocking I/O when speaking to the DB. PHP's problem is its synchronous nature, but Swoole easily bypasses that limitation. Btw. Swoole is not written in PHP. It's C++. It's compiled as an extension for PHP.
- az123456 7y agoBeen doing PHP for 12 years with some fairly high traffic sites under my belt. Switched to Kotlin 2 years ago for new projects and haven't looked back. While it's good to see php innovate, some of us already moved on to greener pastures.
- misir 7y agoI hate php because: even if I used it for ~3 years I had to google how to send GET/POST/PUT ... request. There are lots of ways to do that but each method has its own issues. I'm now using dotnet core and happy with it's orm/speed/infrastructure l/productivity/...
- muglug 7y agoIf you're sending GET/POST/PUT requests rather than just receiving them, curl_* methods are pretty easy and well-defined. But there are also numerous wrappers & frameworks that can make the process simpler.
- fraktl 7y agoThis is exactly one of my points - and don't get me wrong - you're to blame here. Let's dissect your post a bit: you had to google how to send GET/POST/PUT TO PHP or FROM PHP? Regardless, PHP doesn't care what you send it, you can send JSON or base64 encoded string. It's completely irrelevant. If you used PHP for 3 years and are unaware of basic HTTP communication - how's PHP to be at fault here? The real problem here is that you imagined something, it didn't work like you wanted it to and the next logical step is to blame the language. This is such a bad way of thinking, I genuinely feel sorry for you. I could pull several projects that deal with input via HTTP in PHP, and they do it more than nicely. Issue is that you're simply - mediocre. And there's no language that can fix it. Btw. my intent is not to insult you, even a mediocre programmer can become a superstar.
- Cthulhu_ 7y agoI think most other languages and frameworks work via a more declarative API - "if a GET request to /this comes in, return that". I had to look it up / remind myself how it works in PHP as well the other day, and it's a bit more involved: - Create a .htaccess file that rewrites /api/x/y/z to /api/index.php/x/y/z - Read $_SERVER['PATH_INFO'] for the /x/y/z - Read $_SERVER['REQUEST_INFO'] for the HTTP method (GET/POST/etc) - Create the response starting with some calls to `header()` - 'echo json_encode($resp);' I'm sure all that is abstracted away in e.g Laravel though. The PHP standard library could also do with an overhaul for modern applications for requirements like this though.
- tylerjwilk00 7y ago# Summary of some of the new changes: ## Union types Specify multiple types public function foo(Foo|Bar $input): int|float; ## JIT Just in time compiler for improved performance ## Static return type Return static of class class Foo { public function test(): static { return new static(); } } ## Weak maps Prevent blocking of garbage collection for improved memory usage when needed private WeakMap $cache; ## ::class on objects Get class type from object like get_class($object) $foo = new Foo(); var_dump($foo::class); ## fdiv function When you don't care about division by zero fdiv($x,0); ## Concatenation precedence Math takes precedence in string concatenation. // this echo "sum: " . $a + $b; // evaluated as this echo "sum: " . ($a + $b); ## Some others - Create DateTime objects from interface - Type annotations for internal functions - Variable syntax tweaks - Breaking changes - Consistent type errors - Reclassified engine warnings - Reflection method signature changes * Note: HN pretty please get improved mark down parsing
- agentultra 7y agoUnion types! This is amazing to see. So many languages these days agree that functions are good. Now they're all adding type systems of one sort or another. PHP has always been a bit behind the curve but good on the developers for pulling in a cool feature like this.
- fs2 7y agoThis is pretty awesome, I've been migrating from C# and NodeJS back to PHP and it's awesome. Want to know why? - Everything is either built-in or can be enabled from an OFFICIAL repository (like functions for bc,xml,etc). No more trusting sketchy npm packages or having to pull in a ton of dependencies that might stop working some day. - It's so fast and elegant to consume a (SOAP or REST) webservice. Visual Studio insists on creating tons of files, obscure web.config settings and other misc. stuff. PHP handles this in a couple of lines. - Development feels natural, every file can be a single class if you want and there are plenty of highly matured frameworks available. I estimate I've slashed development time in half compared to C#, less bugs and less security issues (verified through two independent code auditors). Even large projects are easier to work on in PHP compared to C#
- pathartl 7y agoI have to disagree with pretty much everything you've written, because it seems like you're running into issues of a paradigm shift. If I'm going to consume a web service, I am going to write the models in C# and let a JSON deserializer like Newtonsoft.JSON map everything. To me, there's nothing better than having a fully modeled web service. I learn a bit about how the service works when writing the models. I know what the data looks like before I start working with it in my own application. Regarding your web.config note, I guess I don't understand what you're trying to get at. .NET projects tend to throw configuration items into, well, a configuration file. Again to me this is far superior to doing the PHP-industry-standard of having a config.php and chucking a bunch of global variables into it. Putting configuration items behind a parser in a document that you expect the user to edit is good practice. Development feels natural, every file can be a single class if you want and there are plenty of highly matured frameworks available. Maybe this is a note more for the NodeJS space, but a single file per class is the general guideline for C#/.NET. Additionally, I've generally found that the .NET framework and libraries written against it tend to be of much higher quality, are more secure, and are more production ready than most I've worked with in PHP land. On top of that, Visual Studio is a wonderful IDE and is pretty much the gold standard of our industry. I've not had a better experience as a developer than being able to create a .NET Core MVC web application and hit the ground running. I've written anything from 5 line Azure Functions to working with 100k+ line web applications and I'm not sure I could have done it without the excellent debugger available and the very context-aware Intellisense typeahead. In contrast, other than PhpStorm, I find PHP environments to be extremely messy and a bit of a hack to get working properly. If I didn't have some sysadmin background I'm not sure I'd move outside of "debugging" using var_dump(). I was a PHP dev primarily from ~2009-2017 and have been working almost exclusively in C# since.
- kingdomcome50 7y agoI'm going to go ahead and play devil's advocate here and make the argument that iteratively transforming PHP into a Java/C# clone is actually doing a disservice to PHP. The reason PHP is so popular, and it's greatest strength, is that it offers a "simpler" paradigm of development. Many of the latest RFCs accepted (while I agree are great steps forward for the language) may actually reduce it's foothold going forward. That is, they are not a good fit for the community. I see no compelling reason to choose PHP for a greenfield project if, when used in a production environment with a stable framework, you are writing essentially the same code as you would for Java/C#. There is hardly a feature where an ASP.NET core C# project isn't still miles ahead of the same Symphony/Laravel back-end. Hell, with the new Razor-Pages template, you are essentially writing "PHP" in C#... where you get all of the bells, whistles, helpers, type-checking, generics, pattern matching, LINQ etc that C# already offers! IMO (emphasis on the "O") they are missing the point. I don't want my PHP application to "look" just like a Java/C# app. I don't want a `Controllers` directory and `RepositoryInterface`s everywhere... I don't want all of the same ceremony it takes to develop a .NET Core/Spring app copied into PHP. What I want is a composition of "scripts" (functions)! PHP should focus on and develop towards it's strengths not it's weaknesses. Lean in to include. Lean in to $GLOBALS. Lean in to a more functional approach. These are the things that have made PHP so dead-simple/approachable over the years. You want more features? Fine. Add pre-processing directives (akin to .razor). Allow for files to truly be treated as modules. Simplify/abstract templating into the language better. That is, instead of focusing on the kinds of "features" that better-enable OOP (and move away from a composition of "scripts"), focus on making it easier/better to compose "scripts". Make _that_ safer, clearer, more ergonomic. There are _plenty_ of ways to dramatically improve PHP (as a platform) without simply updating the language semantics. The language was _never_ the draw! As many of the comments in this thread indicate/imply, PHP isn't chosen because it is such a great language, rather, it is chosen because it offers an extremely convenient development paradigm. PHP is very-much "batteries included" when compared to its contemporaries[0]. _This_ is why people reach for it over and over again. So instead of changing the vehicle (PHP), how about we give it more/better batteries instead? /devil's advocate How'd I do? [0] I have always found the whole "framework vs raw PHP" debate in the community a bit humorous. The "framework" crowd never seems to really understand that, in many ways, raw PHP is a framework. What other scripting languages automatically parse HTTP requests for you as part of the runtime? Or come with a default "routing" scheme? Or offer built-in templating semantics? PHP gives you all three out of the box.
- bunchOfCucks 7y agoMake PHP Simple Again 2020
- perceptronas 7y agoIs it just me or PHP is trying to become Java? I remember 7~ years ago PHP devs were "mocking" Java and not it kinda feels like its moving there
- didip 7y agowow, even PHP gets union types. More languages really need to adopt union types.
- guggle 7y agoI've used PHP from 1998 to 2016. Things I remember I didn't like about/around PHP: - too many aspects of the language were dependent on config/php.ini. - it had errors and exceptions. I just wanted exceptions. - was not very interesting/useful/great outside web backend. - mb_* functions were not enabled by default - it had no decent REPL. - "reference" libraries had bad APIs or were over-engineered. I'm not sure about the state of these issues now, but frankly I never felt the need to look back. Good to hear there's still progress though.
- amai 7y agoPHP and Perl are as dead as the Diesel engine in 2020. Somehow they are still everywhere, but it doesn't feel right to start anything new with them.