[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip / qa] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology


Thread archived.
You cannot reply anymore.


[Advertise on 4chan]


File: PHP-logo.svg.png (73 KB, 1200x648)
73 KB
73 KB PNG
I actually don't mind writing in PHP. Why do people say it's so bad?
>>
>>103225316
Midwits that masturbate over coding language rather than valuing the end result. It's funny too because PHP is so out of style now yet so useful that it's become a by default six figure coding language because new coders only know zoom zoom languages. PHP more or less solved all the core problems going into PHP 7 and to this day is the best low cost server language especially if you don't want to be raped and overcharged by cloud services.
>>
>>103225316
prove it, post a code snippet you wrote that you are proud of
>>
>>103225316
because it filters retards who think they can get the same job done with javascript
>>
>>103225442
<?php
echo "nigger";
?>
>>
>>103225592
Not a real PHP dev, you don't close the <?php tag in files with only logic. Helps with catching errors related to whitespace.
https://www.php.net/manual/en/language.basic-syntax.phptags.php
>If a file contains only PHP code, it is preferable to omit the PHP closing tag at the end of the file.
>>
>>103225667
Shit like this is why nobody takes the language seriously.
>>
For the backend, if I don't want to use Node.js (which I think is shit, let's be clear), what alternatives do you recommend?

PHP seems like the only 'decent' choice to me since neither java nor python seem like an excellent way to me

>inb4 golang, C++, rust
I would avoid stuff for autistics
>>
>>103225719
Unironically ASP.NET Core + EF Core. Ignore all the insane bullshit about DDD with entities.
>>
>>103225752
Does Asp.net also work on Linux? Maybe I'm confused with WPF...
>>
>>103225772
Yes, .NET Core has always been cross platform. Actually MS just calls it .NET now since .NET Framework is deprecated. So-called .NET 5 would have been .NET Core 3.2 or 4.0 in the old naming system.
>>
>>103225592
<?="nigger"?>

You don't need more
>>
>>103225345
>and to this day is the best low cost server language especially if you don't want to be raped and overcharged by cloud services.
Apache + mod_php still the best setup for hosting thousands of low to medium traffic websites. Can't do that with any other language.
>>
>>103225316
it's the one of the worst language ever created, certainly the 2nd worst mainstream language after Cobol
>>
>>103226011
nginx + a static site generator is still the best setup for hosting thousands of low to medium traffic websites.
>>
>>103226039
My clients don't always just want static sites though, so thats a non starter.
>>
>>103226039
lighttpd is faster than nginx and supports htaccess.
>>
>>103226011
>>103226039
What do you use for high traffic websites? Isn't php perfect for that?
>>
>>103226135
For high traffic websites you usually have a reverse proxy that points to a cached version of the page, you don't want to put too much load on the server (mainly the database)
>>
>>103225861
overkill
> echo "nigger" > file.php
> php file.php
>>
People are retarded, PHP is great, especially if you first learn to code vanilla and then use a framework like Laravel. Shit's efficient enough for a ton of projects and development speed is better in the long run than most other solutions.
>>
>>103226135
What I'm more interested in is a better setup for tons of low traffic websites. With high traffic websites there a million solutions out there just pick your favorite, language doesnt even matter either. But PHP is pretty much the only solution for 1000+ low traffic websites. Thats because when no one is accessing your website, there's nothing running unlike Node, Python, Java, etc. Server less is an option, but you either pay out the ass to a provider or set it up yourself which sounds like a giant pain in the ass, and doesnt sound much better than just apache + mod_php or nginx + phpfpm.
>>
>>103226135
Any high traffic website is basically a complex setup of caching shit and distributing shit into separate instances.
>>
>>103225316
times up OP >>103225442, you lost
>>
>>103225719
wasn't deno 2 really good or some shit now

i personally would avoid a js backend because if you're gonna do any math, js' shitty float casting is gonna give you a hard time
>>
>>103225719
Python is perfectly fine, I have no idea why you're afraid of it.
>>
>>103225752
unironically this. I am using PHP + swoole now, but if I could switch without too much effort, would certainly pick c#
>>
>>103225719
>I don't want to use Node.js (which I think is shit, let's be clear)
>>inb4 golang, C++, rust
>I would avoid stuff for autistics
Based. It is rare to see men of reason on this board.
As others mentioned, go with C# if you don't want to go with PHP.
>>
>>103225316
I like Python, it's the best language for getting shit done along with JS, Java and C#.

C++, Rust, Go trannies can btfo.
>>
>>103225316
it used to be bad, most programmers today recognize that php is good now. But the thing is even when it was bad it was actually better than the alternatives. This is something that is not recognized because people have shitty memories and some weren't even old enough to have to choose a language to program for the web.
>>
File: aro0vgbkv11e1.jpg (94 KB, 1066x817)
94 KB
94 KB JPG
>>103225316
>Why do people say it's so bad?
Many reasons.
First, and most important, is that PHP allow you to shoot in your foot very easily, and unfortunately, PHP is often the first language for many people when they actually start to program (aka, getting a job). This lead to some of the most disgusting piece of trash code that you will ever see. It is not strange to see html code and sql being handled in the same file because the poor dude who did this did not knew better and he kinda just wanted to keep his low paying job.
Second, PHP is by far the lowest wages. This just exacerbates the sad reality that everyone who is not fucking retarded learn something else.
Third, PHP was created for internet 1.0. It helped to shape "internet 2.0", but ohhh boy, it struggles with new stuff. Everything that is not printing text is a fucking hack. Ask anyone who ever installed a very specific oracle db driver on a very specific php version if they still believe in god (they don't).
>>
File: xNEI6KB.png (1.21 MB, 1080x1080)
1.21 MB
1.21 MB PNG
>>103225694
wtf u talking about nigger its literally the shebang for bash scripts equivalent
>>
>>103231219
>used to be bad
>use 95% of the shit that still is bad
>don't use any of the new features that make php "unbad"

this argument has always been retarded.
t.20yearphpdev
>>
>>103231383
20 years is not enough
>register_globals
and we use the new features all the time
>>
>>103231310
2005 called, and it wants your shitty outdated argument back
>>
>>103231654
Everything I said is true, and you know this.
>>
Why did PHP get so popular in the first place? Why is PHP still used a lot compared to stuff like Node.js, Spring, and ASP.NET?
>>
>>103231842
something about a danish turboretard, sheeps and niggers
>>
>>103231842
incumbency advantage, getting a vps or a more complicated saas setup used to be difficult and expensive while shared hosting with php and mysql was cheap and had zillions of providers. so the early generation of web devs cut their teeth on that.
>>
Php is only for WordPress, otherwise always something better available. It's full of people who learnt it first and never moved on so still popular. Mostly used in freelancing for small businesses. Full of slavs and pajeets who are unable to learn as well and drive all wages closer and closer to 0.
>>
>>103231842
Easy to use, cheap and easy to host.

Made all the right decisions early on. People who used PHP in the beginning didn't use it because it was the best language, they used it because it just worked. It was a language made for people who just wanted wanted a website, but didn't want to pay some developer to do it for them. Also it was dirt cheap to host hundreds or even thousands of sites on the same server back in the 2000s, something no other language could do well back then. And it was all thanks to the php apache module. Every other language you had to pay for a dedicated server, couple hundred dollars a month, because you couldn't share the server with others. With php you could just pay five bucks a month for a shared server. So the choice was obvious.
>>
>>103231842
Quite literally because it was the first web backend-specific language. Absolutely everything that concerns PHP can be explained just by that.
>>
>>103231842
It's easier to program, less bloated, and doesn't have dependency hell problems.
>>
>>103225316
people are stuck thinking php is still 5.6.
php 7 fixed a lot of what was shit about the language. laravel is great but after needing to switch to typescript for work, i struggle to go back to php with the lack of (good) typing. i don't like needing to rely on phpdoc and static analysis
>>
>>103235036
People must be living under a rock, 5.6 is way past EOL and so is PHP 7.
>>
>>103225345
Enlighten me master. I couldn't get it to run in the vscode extension.
>>
>>103225345
it actually happens now.. many actors (or useful idiots) in there, amazon, microsoft, go/rust-related. also a legacy burden.

>>103226011
its a legacy man. other languages control web servers, same as php controls web client (CURL)
>>
>>103225316
I started (re)learning it recently and it's been a nightmare with anything other than the language itself.
the debugger doesn't work, it just doesn't. not in vscode, not in phpstorm.
and even logging messages to the console is convoluted and retarded.
I'm still gonna force myself to learn it because I hate modern javascript frameworks thoughbeit
>>
>>103235606
>can't even setup xdebug
ngmi
>>
>>103235613
it's supposedly installed and working, judging by the logs on the vscode extension
it just doesn't trigger any breakpoints
>>
>>103235606
17 years making apps in php, serving millions of users, never had to use the debugger nor the console.
There is no reason because the app runs and dies with each request, so just dump the errors in the browsers
>>
>>103235653
that's honestly insane
>>
>>103235631
I don't know what your setup is, but do you have the xdebug php extension installed? Do you have the settings for said extension correctly configured? Namely the correct port? I'm not at home right now, so I can't look at my own personal xdebug setup to help. The way the xdebug vscode extension works is by communicating with the php executable as it runs. You should watch a YouTube video on setting it up, or ask a chatbot (duck.ai).
>>
>>103235748
I'll try again later today.
last night was the first time I felt the need to debug the code because it was failing silently, but it was already 1am and I just wanted to make a quick fix and deploy a personal website I'm making, so that trouble with trying to understand why the code wasn't working AND why debugging wasn't working either just added to my frustration
>>
>>103235767
I had my original statement a little backwards, it's the php executable that communicates with the vscode debugger extension. So that means your php executable, wherever it lives, needs to be able to reach your vscode app. If you're running php in a virtual machine, then you'll need to figure out how to make the host network available inside that virtual machine. If it's in a docker container then there's host.docker.internal for Windows and Mac, and something else for Linux I forget. However host is reached, it needs to be setup in the xdebug section in the php.ini file.
>>
>>103225316
because it's literally one of the shittiest languages ever made. it was clearly made by a midwit trying to string together a bunch of C libraries to do basic webshittery and its poor grammars shows this.
>>
>>103235653
>no logs
Truly the php experience. Works for simple marketing pages but gets worse and worse the bigger and more important the page gets.
>>
>>103225316
Inconsistent style. Some functions havenowhitespace others_use_underscores, order of the arguments is inconsistent, == vs ===, some take individual boooean arguments others TAKE|CONSTANT|BITS typing is inconsistent, if you give a type to a class attribute it fails when you try to change it but it doesn't when it's a typed function argument.
They added traits but you can't check if a class uses a trait like you can with instanceof, instead you have to loop over all traits it uses and do a string comparison. Functions that open a file in your filesystem can open a file from the internet and there's no way to prevent it unless you check it yourself before passing the path to the function. Declare strict is not strict enough, nullables are not nullable enough, can't type arrays, stdclass is dangerous and slow, magic functions make reading code hard. Converting array of arrays to JSON is a pain in the ass because an empty array that is supposed to be a {} is encoded as a [] and then your front-end js fails so you need to traverse the arrays and cast them to objects (the difference between array and dictionary/object is if the keys are ordered numbers or not, remove one item in the middle and it becomes a dictionary, you need to re-sort it.).
I could go on, this is just off the top of my head.
>>
>>103235952
And yet I still php because the frameworks are batteries included, they work with mysql or postgres without code changes, with migrations If I need a queue, it's right there, need a delay? Just add it. Need cache? It's right there, redis or memcached or file based? It's just configuration. Need a whole admin backend for the database with custom fields? It's right there. Do I need commands that use features of the website? Right there, there's even a command to generate the boilerplate to make them, to make anything. Do I need middlewares for jwt, openid, etc? Right there.
I hate it and I hate that it has everything ready to use because it keeps me chained to it.
>>
>>103235952
>Inconsistent style. Some functions havenowhitespace others_use_underscores, order of the arguments is inconsistent
Rasmus Lerdorf addressed this, and PHP is perfectly consistent, just not in the way you think. PHP was originally meant to just be a wrapper around C, so all of the names and argument orders come from the underlying functions that it is wrapping.
>>
>>103235989
Also I have proper logs no printing errors in the client like this peasant >>103235653
And xdebug works just fine if you need a debugger. Arrrgghhhh!
>>
>>103226075
>lighttpd is faster than nginx
wtf? based on what?
>>
>>103236006
It's still inconsistent. The functions haven't been renamed, the order of arguments haven't been fixed. They can't fix it because of backwards compatibility. They'll never fix it unless they want a php 4 vs 5 situation again.
>>
>>103235952
> style
can choose your own style, its not inconsistency.
> internals style
ye, those reflect underlying C APIs. i think thats good for education, one could become familiar with C declarations, so PHP=>C would be easier. again, your API wraps could be perfectly named and styled.
> recent internals style
ye, they author screwed up, should delete it from the core and rewrite as plugable/unplugable extension.
> traits
skill issue. checking which trait is used wrong.
> "streams", "stream wrappers" to network
i fully agree, should delete them, i will. couldnt even find an option to disable them at php.net.
> strict is not strict enough, nullables are not nullable enough
decipher. now it sounds like a whine
> can't type arrays
arrays are sets of pointers to values, no need to bring types in there. what for?
> stdclass is dangerous and slow
again, sounds like trooner statement. danger danger cock in anger
> magic functions make reading code hard
nope, they have double __ which point out they are special, __invoke, __get, __set.. one already knows after single glance
> Converting array of arrays to JSON
what for? use PHP arrays as configuration, its better than JSON or almost any other format except livescripts
> empty array that is supposed to be a {} is encoded as a []
theres JSON_FORCE_OBJECT but its better to refrain from sending anything, dont send that empty key, because it is usually a key with empty array value. dont specify.
> remove one item in the middle and it becomes a dictionary
dont put it in there the first hand
>>
>>103236150
It is consistent, but at the time, C was very popular, so I understand why they did it this way.
>>
File: 1724889502745773.png (233 KB, 680x797)
233 KB
233 KB PNG
Use Rails
>>
>>103236224
Kek why go from bad to bad but with more whitespace?
>>
>>103225316
Probably because they haven't used it in two decades so the PHP in their minds is actually version 3, not 8. And there's a ton of legacy code written in PHP that just sucks so people associate the whole language with stuff like that.
>>
>>103226075
Why do people always pretend a database backed CMS has to be heavy and slow? RDBMS are more efficient than everything you will ever write and if you're really that low on resources you could write your server side code in C like http://blog.fefe.de/ .
>>103226075
>faster than nginx
>supports htaccess
How is that possible?
>>
PHP is just so easy to get things up and running quickly. it barely takes any configuration to get a new server configured to host web listeners that can run for years without worry.
<?php
header("Content-Type: application/json");
$input = file_get_contents("php://input");
try {
$data = json_decode($input, true);
if (isset($data['message']) && $data['message'] === "ping") {
echo json_encode(["response" => "pong"]);
} else {
http_response_code(400);
echo json_encode(["error" => "error"]);
}
} catch (Exception $e) {
http_response_code(400);
echo json_encode(["error" => "invalid"]);
}

then just run that in command line, add it to cron, and run automated security updates on the server. i have production servers with more complex APIs that have been running untouched for over a decade, and it took less than a day of work.
>>
File: oompa_loompa_10201.png (194 KB, 599x483)
194 KB
194 KB PNG
>>103225316
>Why do people say it's so bad?
Like all langues it allows many foot-guns, but it's also simple enough of a language that early on when documentation was suck-ass, people were making more foot-guns and the junior devs gave php a bad rap. Simple-as.
>>
>taking web dev class
>it's all PHP
>finally start working on course project
>has to be remotely hosted on free service
>make account
>password contains FuckThisClass
>going back over the requirements
>there's an SQL database
>I'm unironically going to have to hardcode my credentials in
Should I just keep my password as it or change it. This class has made me not hate all the fucking Python bullshit as much that was forced down my throat.
>>
>>103236908
nope, you cant say it like that. first goes WEB SERVER then goes PHP SAPI module FOR that web server :]

APACHE 2 web server is just so easy to get up with PHP apache2handler SAPI module and running!

when web server will be an extension to PHP then one could word it like:

PHP is just so easy to.. with WEB SERVER X extension and Y glue library
>>
PHP is the GenX of the programming world.

Your welcome for getting Trump in, now fuck off and leave us alone.
>>
>>103231842
Because it's literally a language made to make dynamic HTML pages.

<title><?= $title ?></title>

That's all you need to know.
>>
>>103235683
Anon, you can literally create a perfect local PHP environment that mirrors you web server. I have never had a web server that behaved differently than my local environment.

>>103235903
There is no such thing as an important web page. If your PHP code is so complex you can't do basic debugging you are literally using the language incorrectly.



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.