PHP – The Right Way(phptherightway.com)
phptherightway.com
PHP – The Right Way
https://phptherightway.com/
332 comments
It's a decent website - a useful collection of information and links to additional information, that can serve as a starting point to learn more. For those who use PHP, or for those who'd like to learn to use it, this might be useful resource.
The same thing can't really be said of the comments in here though. I don't see how emotionally charged debates over what is the "best" or "worst" language, help anyone.
It's almost as if some people can truly have their ego shattered, by someone on the internet liking another language than they do...
Couldn't we just agree that there is no "best" language for every possible use case, and that everyone is allowed to like whatever language they want to like? It's not like the whole bickering is going to change anyone's opinion.
The same thing can't really be said of the comments in here though. I don't see how emotionally charged debates over what is the "best" or "worst" language, help anyone.
It's almost as if some people can truly have their ego shattered, by someone on the internet liking another language than they do...
Couldn't we just agree that there is no "best" language for every possible use case, and that everyone is allowed to like whatever language they want to like? It's not like the whole bickering is going to change anyone's opinion.
A language that changes the semantics of functions between minor versions has no "right way".
"count()"less examples of crap. I have currently two weeks of code migration behind me because code running correctly on 7.0 fails on 7.3 -- while I see the reason for change was necessary I also see the hopelessness of rebuilding a flawed house with a fundament build on a pile of manure.
And the good news given to me by a colleague is that they pulled the same stunt going from 7.3 to 7.4. It's like depending on stumbling alcoholics instead of language designers.
Not much has changed since core devs tried to mitigate an overflow by testing for "$variable < MAXINT".
And the good news given to me by a colleague is that they pulled the same stunt going from 7.3 to 7.4. It's like depending on stumbling alcoholics instead of language designers.
Not much has changed since core devs tried to mitigate an overflow by testing for "$variable < MAXINT".
PHP is actually a really decent option these days. And several libraries and frameworks built around it are flourishing.
The best features of PHP are:
1. Core API of stateless functions. Compare this to the bootstrapping requirements of, say, Java or Python;
2. CGI-like resource management in that you tear down everything after a request. Many people get upset at, say, the "global" keyword but "global" here just means "request-scoped". There are no STW GC pauses and it's difficult (but not impossible) to leak resources;
3. Executing code for a request is single-threaded. This is almost always what you want; and
4. PHP's copy-on-write arrays (that are really hash maps) that maintain insertion order are so incredibly useful and is almost always what you want.
Crapping on PHP for things like function inconsistency (eg functions that use underscores vs those that don't, needle/haystack inconsistency) is a tired cliche and boring at this point. It really adds no value complaining about things that just don't matter and/or are historical.
My biggest grievance is that Hack (FB's fork) is basically better in almost every way. The collection types (vec, keyset, dict) are better (eg less weird coercion defaults). The type system is leaps and bounds ahead of anything PHP has. Nullability as part of the type system is amazing. It's a shame Hack didn't become the dominant dialect.
As for the book, I went through it and it's really solid. Good job to the authors and maintainers. It covers a lot of issues like register globals, sanitizing input, Unicode and so on. It also has links to more detailed information on any of these topics.
1. Core API of stateless functions. Compare this to the bootstrapping requirements of, say, Java or Python;
2. CGI-like resource management in that you tear down everything after a request. Many people get upset at, say, the "global" keyword but "global" here just means "request-scoped". There are no STW GC pauses and it's difficult (but not impossible) to leak resources;
3. Executing code for a request is single-threaded. This is almost always what you want; and
4. PHP's copy-on-write arrays (that are really hash maps) that maintain insertion order are so incredibly useful and is almost always what you want.
Crapping on PHP for things like function inconsistency (eg functions that use underscores vs those that don't, needle/haystack inconsistency) is a tired cliche and boring at this point. It really adds no value complaining about things that just don't matter and/or are historical.
My biggest grievance is that Hack (FB's fork) is basically better in almost every way. The collection types (vec, keyset, dict) are better (eg less weird coercion defaults). The type system is leaps and bounds ahead of anything PHP has. Nullability as part of the type system is amazing. It's a shame Hack didn't become the dominant dialect.
As for the book, I went through it and it's really solid. Good job to the authors and maintainers. It covers a lot of issues like register globals, sanitizing input, Unicode and so on. It also has links to more detailed information on any of these topics.
Actually, that make me remember statements of Linus Torvalds on Git at Google Tech Talk Conference:
But I did end up using CVS for seven years at a commercial company and I hated it with a passion. When I say I hate CVS with a passion, I have to also say that if there are any SVN users in Subversion, users in the audience, you might want to leave because my hatred of CVS has meant that I see Subversion as being the most pointless project ever started, because the slogan for Subversion for a while was, CVS done right or something like that.
And if you start with that kind of slogan, there’s nowhere you can go. It’s like — there is no way to do CVS right. So that’s the negative kind of credit.
https://singjupost.com/linus-torvalds-on-git-at-google-tech-...
But I did end up using CVS for seven years at a commercial company and I hated it with a passion. When I say I hate CVS with a passion, I have to also say that if there are any SVN users in Subversion, users in the audience, you might want to leave because my hatred of CVS has meant that I see Subversion as being the most pointless project ever started, because the slogan for Subversion for a while was, CVS done right or something like that.
And if you start with that kind of slogan, there’s nowhere you can go. It’s like — there is no way to do CVS right. So that’s the negative kind of credit.
https://singjupost.com/linus-torvalds-on-git-at-google-tech-...
I totally expected it to be a troll site. It's actually sensible advice.
But, really, I suggest using other tools. We have nicer tools now.
But, really, I suggest using other tools. We have nicer tools now.
Just wanna dump a bunch of similar PHP sites you might find useful:
(The only proper) PDO tutorial: https://phpdelusions.net/pdo/
Organize a php project according to industry best practice: https://github.com/thephpleague/skeleton
PHP Best Practices - A short, practical guide for common and confusing PHP tasks: https://phpbestpractices.org/
Modern PHP Cheat Sheet - A to-the-point summary of all awesome PHP features: https://front-line-php.com/cheat-sheet
Laravel, PHP, JavaScript: https://freek.dev/
PHP security: https://paragonie.com/blog
(The only proper) PDO tutorial: https://phpdelusions.net/pdo/
Organize a php project according to industry best practice: https://github.com/thephpleague/skeleton
PHP Best Practices - A short, practical guide for common and confusing PHP tasks: https://phpbestpractices.org/
Modern PHP Cheat Sheet - A to-the-point summary of all awesome PHP features: https://front-line-php.com/cheat-sheet
Laravel, PHP, JavaScript: https://freek.dev/
PHP security: https://paragonie.com/blog
PHP is still full of awkward decisions.
One that baffles me is that 8.0 changed it so all scripts default to a "C" (i.e. english, ascii-only) locale. [0]
So this is now a scripting language that requires you to call `setlocale` for every script manually.
Contrast python, which tries to fix the locale so it's at least UTF-8 aware. [1]
[0]: From https://www.php.net/manual/en/migration80.incompatible.php "The default locale on startup is now always "C". No locales are inherited from the environment by default. Previously, LC_ALL was set to "C", while LC_CTYPE was inherited from the environment. However, some functions did not respect the inherited locale without an explicit setlocale() call. An explicit setlocale() call is now always required if a locale component should be changed from the default. "
[1]: https://www.python.org/dev/peps/pep-0538/
One that baffles me is that 8.0 changed it so all scripts default to a "C" (i.e. english, ascii-only) locale. [0]
So this is now a scripting language that requires you to call `setlocale` for every script manually.
Contrast python, which tries to fix the locale so it's at least UTF-8 aware. [1]
[0]: From https://www.php.net/manual/en/migration80.incompatible.php "The default locale on startup is now always "C". No locales are inherited from the environment by default. Previously, LC_ALL was set to "C", while LC_CTYPE was inherited from the environment. However, some functions did not respect the inherited locale without an explicit setlocale() call. An explicit setlocale() call is now always required if a locale component should be changed from the default. "
[1]: https://www.python.org/dev/peps/pep-0538/
But what's the point?
The beauty of perl scripts, and later php templates, was in their BASIC-like simplicity. They were not secure or structured in any way, but very accessible.
Once you add these frameworks, you realize you could have started with Python or Java in the first place and get more mature infrastructure and better language along the way.
The beauty of perl scripts, and later php templates, was in their BASIC-like simplicity. They were not secure or structured in any way, but very accessible.
Once you add these frameworks, you realize you could have started with Python or Java in the first place and get more mature infrastructure and better language along the way.
> Right now PHP does not support Unicode at a low level. There are ways to ensure that UTF-8 strings are processed OK, but it’s not easy, and it requires digging in to almost all levels of the web app, from HTML to SQL to PHP. We’ll aim for a brief, practical summary.
https://phptherightway.com/#php_and_utf8
This is a web language? PHP still has these kind of issues because of its culture: Get it done now and ignore any future costs.
https://phptherightway.com/#php_and_utf8
This is a web language? PHP still has these kind of issues because of its culture: Get it done now and ignore any future costs.
That sure is a big a web page for having no table of contents!
There’s a ToC on https://leanpub.com/phptherightway but I can’t link directly to it as the in-page link uses JS. (I’m on mobile though, so I can’t read the source. Maybe there’s an anchor someone else could link to.)
There’s a ToC on https://leanpub.com/phptherightway but I can’t link directly to it as the in-page link uses JS. (I’m on mobile though, so I can’t read the source. Maybe there’s an anchor someone else could link to.)
I want to like PHP, but it seems that there are so many better/modern alternatives out there, IMHO Go and Rust are the most notable new ones, Go is almost (if not yet) ahead of PHP in terms of community and resources (learning and packages), while Rust still needs a few years to establish (the async issue and few others) and the maturity of the ecosystem, there are no killer solution yet (maybe there will never be).
I tried PHP last year (or should I say Laravel) and didn't found any good, the type system is bad for a project like Laravel, you have too many different files where you declare things and the type system doesn't now, so you end up without autocompletions (and warnings or errors from the php interpreter) you only catch those at runtime (I'm too used now to get the errors before run a project, or at least get a hind from the editor/IDE).
I tried PHP last year (or should I say Laravel) and didn't found any good, the type system is bad for a project like Laravel, you have too many different files where you declare things and the type system doesn't now, so you end up without autocompletions (and warnings or errors from the php interpreter) you only catch those at runtime (I'm too used now to get the errors before run a project, or at least get a hind from the editor/IDE).
Slightly of topic, but is Hack a thing outside of Facebook? I'm a little thrown off by the confusing standard library of PHP, but I don't know if using Hack instead would solve more problems than it creates.
My problem with PHP is that it solves the issue of code reuse the wrong way round.
In other languages, you can import code like this:
In PHP, it is the other way round. Every piece of code needs to try avoiding namespace conflicts by prefixing the code with something like this:
In other languages, you can import code like this:
import mail as mailer
The external code ("mail") does not have to make assumptions how it will be called when it is used.In PHP, it is the other way round. Every piece of code needs to try avoiding namespace conflicts by prefixing the code with something like this:
namespace Illuminate\Mail;
Hoping the namespace (here "Illuminate") will not clash with other code.Updated in January but not really up to date. It doesn't mention union types, the nullsafe operator, matching expressions and a lot of other features you can find here: https://stitcher.io/blog/new-in-php-8
Maybe not everything is "the right way" but at least the nullsafe operator is, I think.
Maybe not everything is "the right way" but at least the nullsafe operator is, I think.
[deleted]
I'm trying to learn https://haxe.org , so that if some target language does not work, I could use some other target language. Currently I have hard time updating to newer version of Node.js, dependencies etc. I tried to code something with PHP 8.1 directly, but I presume any following update could change syntax etc.
Is there a page like this for c# dot net?
Why not install using asdf ?
The reason why people now care about PHP is that, decades ago they thought PHP would the right way to develop projects, now they are stuck, because they cannot get rid of PHP any more. If you look at any well grounded projects, they try to avoid PHP at all cost. Only handful amount people are responsible for core development. Decision are made based on "copying" other languages like Java, plus you always end up using lots of tools just to make your code safer.
There are tons of tools to get things done, PHP is one of the worst ones.
There are tons of tools to get things done, PHP is one of the worst ones.
• CGI-like execution model when used for the web, making resource leaks very difficult and encouraging scalable design
• not only integers and floats, but also strings, lists and dictionaries as mutable value types (copy-on-write) — this is a big difference from JavaScript and Python
• unusually for a dynamic “scripting” language: true classes and interfaces, and optional type declarations enforced by the runtime
• a standard library that doesn't require import statements!
• (a very new feature:) fibers, a way do asynchronous execution without every function in the callstack having to be aware of it
• binary-safe strings without presumptions from the language about what encoding is in use
• a very nice package manager
• a highly optimised runtime
But its history has made it a quite messy language which can be frustrating to learn, and which will always carry a higher mental burden than something like Python. It is a shame.