The content is great. I like how you start off teaching the language by showing how to execute simple programs from the command line (I learned that you don’t need the `-f` option to execute a file). I’ve come across far too many PHP introductions that confuse the new learner by attempting to get them to set up a web server (usually Apache) and then all the strings have to be wrapped in HTML markup when printed. There’s a lot to be said for keeping it simple for teaching the essentials of a language.
The site is cleanly and beautifully formatted and I love how lightweight it is: HTML files, a CSS file, a JS file and an image. It’s such a refreshing change from the thousands of visually cluttered sites that make hundreds of resource requests (most of them third-party) and whose content is not visible without allowing third-party JavaScript. When I completely disabled JavaScript on this site, all I noticed were non-essentials such as Solarized syntax highlighting and the Table of Contents; I could still navigate through the site using the Previous and Next links (and of course, the browser’s Back button).
I regularly use bash and I have learnt HTML, CSS and JavaScript in the past. If I had to use only one of these resources - OP's site or PHP the Right Way - which would you recommend I use? To put it some other ways - does OP's site adequately cover best practices? Is PHP the Right Way targeted aimed at fully-fledged programmers who want to pick up PHP?
Thanks for reading! This is still a young project with room for improvement and new sections. I’m already planning some content for building web pages, database access and package management with Composer. I wrote an announcement post over on dev.to if you want to read more about how the site was built: https://dev.to/restoreddev/announcing-php-apprentice-coc
Very well done, there’s a lot to help a novice PHP developer. I feel like the next chapters I’d love to see would take those concepts and apply them to building something. Everything so far unless I missed it is focused on the backend but it’s important to show that it’s also possible to use it as a front end and what the modern approaches to doing that are.
Thats a good point. PHP is a general language, but used almost exclusively for web development and most websites now use a framework (symfony/laravel......) etc.
I'm learning symfony framework after my micro framework of choice lost its support (Silex..).
Someone showed me the free video cast howto build a basic symfony site. I though it was pretty good. Like many of these, the basic tutorials are free, but its a subscription site.
Nice job and well written. A nice addition would be how to use pdo. I'm appalled by the number of ressources I see online which are using the old mysql api.
> I'm appalled by the number of ressources I see online which are using the old mysql api
Recently authored articles? We have an internet filled with 20 years of PHP tutorials, and unfortunately for beginners there's not an easy way to evaluate if something utilizes modern best practices or is an Experts Exchange post from 2001.
I find strange you can't down-vote a link on Google, it should exist and Google should take it into account specially for technical links (less so for opinions articles or anything political)
That's the problem, in technical links popularity (as in number of visits) is not linked to correctness, that's one of the reasons StackOverflow is so useful, because the top-voted answer is like 99% of the times the most correct (useful) one.
Unfortunately, such edits are rarely accepted. The intent was for the site to be more wiki-like, but these days "respect the author's intent" is the prevailing wisdom. The cases where someone edits a top answer with a significant correction or update are very few, and require overwhelming community support or they'll be reverted.
This is particularly distressing in the case of security vulnerabilities. Vulnerable code being copied from Stack Overflow into consumer applications isn't hypothetical, it's been empirically demonstrated (https://www.aisec.fraunhofer.de/en/stackoverflow.html), yet the community and company refuse to accept responsibility and address the problem. (Of course the developer creating the application is more responsible, but Stack Overflow is in a position where they could help protect innocent end users and the common good.)
Pinning of accepted answers to the top of the list was a good idea when the site was young. These days, it prevents updated better answers from taking the place of ten-year-old misinformation.
Yep, the plethora of out-of-date resources is what I'd place as the main issue with PHP today. I usually steer people to use the Laravel framework since it makes it difficult to write bad/dangerous code.
Can confirm. I've written one site with PDOs and a lot of sites with the old stuff. PDO is definitely a different feel to wrap around, and more resources on it would definitely be good.
For what it's worth though, my understanding is mysql_ functions are removed completely as of PHP 7. So that old documentation will just not work, rather than teaching people the least secure option of how to write their website.
similar. got a call from someone re: a site built on a homegrown mvc framework from 2000/2001 (when PHP4 was just out).
this call came in late 2017 saying "hey, we migrated the site and it doesn't work". There was some change in PHP5.6 and the initial PHP4 code had some "by reference" class stuff that wasn't working any more. It was a small change to get it working again, but there was enough PHP4 in it that a move to PHP7 wasn't going to work without a lot of work. I'd suggested a rebuild, which... wasn't too well received. Pointing out that they'd had 16 years of functionality on a web codebase (with no other costs) was probably as much ROI/value as you'd ever be able to get out of anything.
I haven't used PHP in around 6 years (running PHP 4 I belive); has the language improved ? My biggest complaint was that the API was incredibly inconsistent, but that seemed like it could be improved in later versions if they weren't afraid of breaking backwards compatibility.
One of the best things of PHP today is the ecosystem. The PSR [0] interfaces let you build your own framework using libraries from the major frameworks or independent libraries seamlessly.
I have been using PHP for a new job after not using it since PHP 4 too but I was also a very immature dev back then. I quite like it. It's not perfect and it still lacks some things but it's very easy to put something together. I think that my biggest problem is actually that it's too easy, which makes some people write code that it's a bit too sloppy and hard to understand, creating a possibly huge technical dept.
PHP 7+ is a totally different world from 4. It’s actually a real programming language now. The massive API redundancy is still there, but you have classes, namespacing, etc.
class A {
public int $id = 0;
public ?Foo $somefoo;
}
The language has evolved slowly but surely, and it's now much harder to make obvious mistakes thanks to a bunch of good-quality static analysis tools (one of which I authored).
It has improved a lot in that time and I find it decent to work with now that there's decent dependency management with Composer and a good Rails-like framework in Laravel.
I love PHP, it was my first “real” programming language, and I’m glad there are still people trying to make it easier to adopt.
Having skimmed through several of these chapters, though, I just feel like it’s too similar to the official PHP docs, even down to the TOC.
Wouldn’t it have been better for everyone to put this effort into improving the docs, rather than developing yet another book in a silo that likely won’t have the longevity we’d like?
I started with foundational concepts which will overlap some with the official docs. The advantage of my site is I wanted it to be more readable, since the official docs can be hard to navigate. In the future, I want to cover topics like Composer and Slim which would not be appropriate for PHP.net.
That’s cool and does give the comprehensive approach some credence, but still feels like duplicated effort and the potential for outdated content (on both sides).
FWIW, I don’t think giving a more readable aspect to the official docs would be bad. It’s already got way more of that feel than it did in PHP 4, when it had more of an MSDN auto-generated parameter documentation feel. With the clear sections and code snippets I think both could be achieved with little extra effort.
Imagine this kind of reception for any other content. Someone spends a year into composing a new symphony and the reviews go "I love live music but wouldn't it have been better if the composer would have re-orchestrated a familiar classic rather than developing a whole new score that won't be performed as often as we'd like?"
I can't find a better language to use in 2019 in the backend if you are developing a website.
Is there a better language built for rapid web application development. You could debate which is better rails/laravel but in 2019 I would learn php.
You may suggest Go, python, .net, node, Perl or java. They could be used but each only offers an advantage in certain situations and make development slower or have another disadvantage.
If you want to make a website using php is the simplest easiest fastest choice available.
I think it’s still one of the pragmatic language around.
The ‘quick and very dirty’ parts are still there, the ‘clean and efficients’ bits have been added, and there’s a ton of still runnable doc and code lying around.
All of that is a blessing and a curse of course, but I think that makes it a unique proposition.
Yeah, that was my first reaction as well! With the chapters being this short (which itself is great) it would be really nice to be able to use the arrow keys.
Not sure if the dev will see this, but it would be nice if it was a little easier to get to the table of contents as well. My suggested code change. (quick a dirty example)
Nice little reference for anyone who already knows how to program, but might not know PHP. For anyone else, this isn't really going to help. There seems to be no explanation of _why_ you would want to do anything here or even how it relates to a goal. Who is your audience?
IMHO, I think the audience is me. I can program (perl, java, c++). I know that php is easy but that there are many traps. I need a book to be able to develop quickly with sane practices. The official documentation contains too much old crust.
Too much old crust, but as other commenters around indicate, this isn't really solving that either: it doesn't talk about best practices or even highlight where the sharp edges are (EOLs and Namespaces are mentioned elsewhere).
Because the examples given in this "book" teach a bad coding style and explain nothing in detail.
If a trainee only used this to prepare for the final exams and I was to ask a more in depth question he would propably fail.
Example:
"Why do you use double quotes everywhere?"
Most probable answer:
"Because I can use variables and the backslash-n thingies everywhere and its more convinient than using single quotes."
Example:
"Why do you use '. "\n";' instead of the PHP_EOL constant?"
Most probable answer:
"What is PHP_EOL?";
Example:
"Why aren't you using namespaces anywhere?"
Most probable answer:
"What are namespaces?"
Altough this might be a german perspective but I would not hire someone that presents me this kind of code.
And for anyone saying "But this is only one book to learn the basics?" why not learn it the right way from the start?
The site is cleanly and beautifully formatted and I love how lightweight it is: HTML files, a CSS file, a JS file and an image. It’s such a refreshing change from the thousands of visually cluttered sites that make hundreds of resource requests (most of them third-party) and whose content is not visible without allowing third-party JavaScript. When I completely disabled JavaScript on this site, all I noticed were non-essentials such as Solarized syntax highlighting and the Table of Contents; I could still navigate through the site using the Previous and Next links (and of course, the browser’s Back button).
Kudos!