News for hackers. Stuff that matters.
Re:PHP vs Node js... Let's be honest: Node.js couldn't kill ... by krapp on Friday May 05, 2017 @05:44PM (#14277045)
>Don't people use frameworks these days such as symfony, silex and laravel etc

People should, Composer (with PSR autoloading) and nikic's FastRoute get you most of the way to a really nice, lightweight meta-framework barring anything else, for practically nothing. There really is no excuse for the "URL points to a file" model to be a thing anymore.

But a lot of legacy PHP code doesn't do that, and likely a lot of newbie code doesn't, because they follow old tutorials, and that model is faster and simpler.

Not even Wordpress uses routing AFAIK.

Re:PHP vs Node js... Let's be honest: Node.js couldn't kill ... by mysterydip on Friday May 05, 2017 @07:14PM (#14277523)
Honest/naive question: why not? Plenty of mvp or weekend projects can get by easily with url=page. If it's faster and simpler, what's wrong with doing it? Surely there's room for both on the intetnet.
Re:PHP vs Node js... Let's be honest: Node.js couldn't kill ... by colemickens on Friday May 05, 2017 @11:35PM (#14278527)
How exactly is it either faster or simpler...? Especially when any of the frameworks just come with it configured out of the box?

sure, if you're writing "Hello world", /index.php is great. For everything else? Not so much.

This reminds me of people saying "version control, that's too hard, I'll just make backups of the src dir regularly".

Re:PHP vs Node js... Let's be honest: Node.js couldn't kill ... by mysterydip on Saturday May 06, 2017 @06:59AM (#14279669)
krapp said so in the comment I replied to, I was roundabout quoting that.
Re:PHP vs Node js... Let's be honest: Node.js couldn't kill ... by krapp on Friday May 05, 2017 @07:39PM (#14277637)
Having a router allows you to not have all of your files be web accessible, by using a single point of entry and a whitelist for all possible paths. Most projects which map PHP files to URLs have everything in the web root.

If it's just a small brochure site with a few pages then it's no problem, but forums and larger projects built like this can leak information and expose vulnerabilities when PHP files which weren't meant to be directly accessed are, such as pages that perform SQL queries expecting variables in context that don't exist when accessed directly, or old config files, text files, open directories, etc.

But "url=page" is still basically routing using the query string, and IMHO so is access control using .htaccess. Any system where URLs are validated and where they don't directly point to files on the server counts.

Re:PHP vs Node js... Let's be honest: Node.js couldn't kill ... by combatentropy on Saturday May 06, 2017 @02:31AM (#14279038)
> Having a router allows you to not have all of your files be web accessible

Having a router may make it easier, but it's not the only way.

You can just put your libraries, passwords, etc., in some directory outside the document root.

    /var/www/example.com/public
    /var/www/example.com/lib
Then you use "include" to get them.
Re:PHP vs Node js... Let's be honest: Node.js couldn't kill ... by krapp on Saturday May 06, 2017 @09:09AM (#14280071)
Having worked on projects with includes within includes within includes, and dealing with global variables defined in one file, used in another and reused elsewhere, it's definitely not the best way and it seems to destroy encapsulation.

If you can keep it under control, though, of course it's no different than includes in C/C++ (it probably literally is a wrapper around the macros.) But modern PHP prefers using autoloaders, so you never actually have to use include statements to begin with. You could just as well define those directories and include them through a Composer setting.

Re:PHP vs Node js... Let's be honest: Node.js couldn't kill ... by combatentropy on Saturday May 06, 2017 @03:28PM (#14281828)
> includes within includes . . . global variables

Yeah, that's a pain. You have to exercise a little discipline. Of course none of my code has that ;)

With hand-typed routing, can't you accidentally define two routes that overlap, so some URLs could match both? The only reason it goes to one and not the other is something random like the order the routes are defined in the file? Like if you defined this route:

  /a/b/c
Then you slept, added a bunch of code, came back in three months and put this in:

  /a/*/c
Now you have two routes that match the same URL. And maybe they're separated by several lines of code, so that the mistake is hard to spot.

You can't do that with a filesystem, put two files in the same place.

Re:PHP vs Node js... Let's be honest: Node.js couldn't kill ... by krapp on Saturday May 06, 2017 @05:26PM (#14282347)
> The only reason it goes to one and not the other is something random like the order the routes are defined in the file?

To be fair, that's not random, that's pretty explicit. And if you're optimizing for speed, short circuiting at the first match is a good idea.

But if you're using a router, chances are you're passing the segments as arguments to some function or method anyway, so route /a/*/c and /a/b/c should both wind up returning the same content if the second segment in both cases is 'b'.

Re:PHP vs Node js... Let's be honest: Node.js couldn't kill ... by developer2 on Saturday May 06, 2017 @02:10AM (#14278982)
>> not have all of your files be web accessible

cough wp-config.php cough

Re:PHP vs Node js... Let's be honest: Node.js couldn't kill ... by omnimus on Saturday May 06, 2017 @04:43AM (#14279355)
Ive read somewhere interview with original author of PHP and he was very strongly against routers and one point of entry index.php . Saying that they are doing webservers job again. Router makes php slower.

I think while it is easier to use files as routing first time you use php.. once you start learn how to program, simple router is much much easier to reason about. Simple router is not the problem when learning php. Problem is clunky language with lot of legacy stuff and that people start with something like laravel that has so much stuff in it that you have to learn 20 concepts at once.