
PHP Apprentice – An online, open-source book for learning PHP - restoreddev
https://phpapprentice.com/
======
Anthony-G
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).

Kudos!

~~~
restoreddev
Thanks! I really made it a goal to keep the site lightweight and simple.

------
txsoftwaredev
Nice job. I would suggest all PHP devs spend some time with
[https://phptherightway.com](https://phptherightway.com). Your resource looks
to be a great starting point.

~~~
lillesvin
Not disagreeing but I usually recommend that people read
[http://www.phpthewrongway.com/](http://www.phpthewrongway.com/) afterwards to
get a more pragmatic viewpoint.

~~~
Aeolun
To be honest, it reads more as someone being salty they don’t understand the
point of frameworks.

~~~
lillesvin
I think you skimmed the article too quick then because there are plenty of
good and well supported arguments in it.

~~~
Aeolun
I think I read mostly to the end before giving up on it.

There’s a lot of arguments, I just don’t think they’re particularly good.

Don’t misunderstand me, there is a point there, but it’s buried under a load
of text.

------
restoreddev
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](https://dev.to/restoreddev/announcing-php-apprentice-coc)

------
xfour
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.

~~~
acomjean
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..).

The symfony documents are ok, but I wouldn't want to give them to someone
starting out. (though looking again, they seem better..)
[https://symfony.com/doc/current/page_creation.html](https://symfony.com/doc/current/page_creation.html)

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.

[https://symfonycasts.com/tracks/symfony](https://symfonycasts.com/tracks/symfony)

------
tangue
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.

~~~
meritt
> 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.

~~~
mattigames
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)

~~~
jordigh
Everything is political. I wouldn't want people to downvote Mercurial links
into oblivion.

Anyway, Google links are pretty much already ordered by popularity.

~~~
mattigames
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.

~~~
ysleepy
Except when that answer is 5 years old and is as wrong as the ExpertsExchange
post from 2001.

~~~
ceejayoz
_Unlike_ EE, though, any user can propose an edit to that now-incorrect answer
(or just edit it outright, if they have 2k rep).

A nice big "this answer is outdated, see [other answer]" note does wonders.

~~~
JeremyBanks
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](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.

------
tombert
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.

~~~
aphextron
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.

~~~
glitcher
Also adding libsodium directly into PHP core as of 7.2 was a big step in the
right direction IMO.

------
chrismeller
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?

~~~
h8hawk
Are there other technical reason's for advocating it, other than your love
because it was your first "real" language?

~~~
wolco
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.

~~~
h8hawk
Thank you. I've looked for this sort of explanation.

------
Geee
The null coalescing operator ?? is not well explained. It returns the first
operand but if it's not set or null, will return the second operand, i.e:

    
    
        $name = $_GET['name'] ?? $_POST['name'] ?? "unknown";
    

In the arrays section, I'd also introduce the $array[] shorthand for
array_push(), i.e:

    
    
        $array[] = $new_element;

------
erusev
Looks great! Perhaps, making it possible to turn pages with the arrow keys on
the keyboard would make it a bit easier to navigate.

~~~
Kiro
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.

------
xemoka
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?

~~~
reacweb
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.

~~~
xemoka
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).

------
smougel
Good job ! Please add something about namespaces.

~~~
restoreddev
It’s on the roadmap!

------
noir_lord
Looks like good material and the formatting is nice so kudos.

------
akhk8726
Well written and easy to read- hugely valuable resource! Can't wait to see
more.

------
DoctorPenguin
Why not teach it better?
[https://glot.io/snippets/f8g0wlar0d](https://glot.io/snippets/f8g0wlar0d)

No wonder PHP developers have a bad reputation.

~~~
mweibel
I downvoted you because your comment doesn't help anybody and is offensive.
Why do you think your example is better?

~~~
DoctorPenguin
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?

