News for hackers. Stuff that matters.
Re:Modern PHP without a framework by godot on Sunday April 01, 2018 @01:09AM (#16726828)
I started a startup in 2013, and I picked PHP for a core language since I had a decade~ experience with it by then and it was a good enough reason to use it. PHP 7 wasn't available yet and nodejs was only starting to take off and didn't seem like the future yet.

Taking learning from previous companies, I've found the main thing PHP was lacking at the time was a good routing mechanism. We obviously don't want to rely on Apache hitting .php files to handle requests. So we used ToroPHP (https://github.com/anandkunal/ToroPHP) for routing, which is a seriously lightweight routing lib. Indeed we used composer and a lot of dependencies, but for our own codebase we used manual includes instead of the autoloader. With the usual PHP production setup like APC with opcode caching enabled and file stat'ing off (later on opcache + APCu), we handled scale extremely well. (mentioning this because a counter-point for manual includes is that many requests would unnecessarily load way too many code files)

As far as codebase maintenance and growth go, that PHP codebase was actually very easily manageable even with manual includes. Having routing solved frees you up to organize your code files in any ways you want. Even today, I have a mini-framework structured this way for myself to start side projects and test ideas with. (Yes, using PHP5 for side projects in 2018 ;)

My point in bringing all this up is that the architecture this article is trying to take you in, seems unnecessarily complicated for PHP.

This past year I've been working in a full nodejs shop and this entire architecture (from this article) reminds me heavily of how a node/express app is structured. Someone else on this thread mentioned modern languages have their architectures converging. This is exactly what's happening. Even as a PHP fan, it makes me feel a bit of "Why use PHP at this point, instead of nodejs/go/python?" while reading this. It feels like if you wanted to go this route, nodejs is a better option on almost all fronts -- language syntax brevity, availability of packages, community, developer-availability. The only reason to use PHP at this point is nostalgia/sticking to PHP syntax.

Re:Modern PHP without a framework by nikita2206 on Sunday April 01, 2018 @05:35AM (#16727507)
The reason to use PHP over JS/Python or Ruby is that PHP supports strict typing and that makes code both more maintainable, understandable (Find Usage feature only works reliably when types are inferrable which is not always the case in those other theee langs) and refactorable.

Now the reason to use PHP over Java or Go is that PHP at this point has a type system that’s on par with Go’s but at the same time it gives you an advantage of fast development process thanks to the lack of need for compilation and/or restarting the container after each change in the code. I’m currently working with Java and before that I had a long experience of PHP, while I personally would choose Java over PHP almost in any case because I value type system features perhaps a bit too much, but I do suffer from those slow turnaround times (compile/restart TomCat) and I can see how it could potentially be bad for the business at early stages especially.

So the bottom line is PHP at this point has a nice balance which is hard to find atm in any other popular languages with evolved ecosystem

Re:Modern PHP without a framework by snomad on Sunday April 01, 2018 @10:04AM (#16728308)
> PHP supports strict typing

Still missing types for object properties :(

Re:Modern PHP without a framework by tylerjwilk00 on Sunday April 01, 2018 @10:33AM (#16728474)
As a work around you can use a private member variable with type hinted setter and getter.
Re:Modern PHP without a framework by linoge on Sunday April 01, 2018 @07:35AM (#16727767)
Isn't proper type system and Java things that shouldn't ever be on the same phrase?
Re:Modern PHP without a framework by treve on Sunday April 01, 2018 @02:21AM (#16727032)
As someone who's been doing PHP for nearly 15 years, but 2 years ago switched to Node.js for a job, I agree. This is even more true when switching to Typescript.

We introduced typing later in the project and wow what a step up in safety and productivity.

Re:Modern PHP without a framework by exclusiv on Sunday April 01, 2018 @03:39AM (#16727221)
Yes. Same with PHP7.