DEV Community

Discussion on: What's the deal with downing PHP development?

Collapse
lucafabbri profile image
lucafabbri • Edited on

In addition to previous comment I would also point out a few things that everyone hates writing php:

  • you need $ anytime you call a variable.
  • you need 2 chars for method calls "->" or "::".
  • at a certain point in your life you'd probably need to know in advance the type of your variables
  • there is a crappy function or library somewhere in your code that might give someone full access to your machine
  • using OO elements along with functions its just confusing, most of the times classed are merely collections of functions with no coherence.
Collapse
tux0r profile image
tux0r

I disagree with the assumption that "everyone" would hate that.

  • $ for variables: yup, so you can see instantly that it is a variable and not a function, a constant or a keyword.
  • type of variables: just prefix them, like you would in JavaScript, Python et cetera.
  • crappy libraries: easy solution, stop using other people's code. :-) That said, if someone can get full access to your machine, you should fire your admin. PHP should not run as root.

The other points: I agree.

Collapse
aleksikauppila profile image
Aleksi Kauppila • Edited on

@tux0r Imo, don't prefix, don't use hungarian notation.

If we get typed properties in PHP 7.4 (or any later version) there's very little ground to cover that isn't typed.

Using type hints everywhere with declare(strict_types=1) fixes a lot of these issues.

@lucafabbri

  • I like the two different method call notations. Clear separation of calls to static methods and instance methods.

  • Not sure what you're driving here, but if someone can't do OO design then what can i say? If you're talking about global functions like in_array() then i agree. Yes they are bad. But frankly, do they really differ that much from static method calls like Array.map() or Math.max()?

Thread Thread
lucafabbri profile image
lucafabbri

Let's say that you are new to PHP and you are bugfixing someone else code. There is a lot of overhead understanding what belongs to global, to user functions and classes. This is not clean. While a class in other languages specifies all namespace in its header, in php you can come to a fall of includes that you need to drive back until you find where the function is. Namespace are actually more clean, easy to debug and extending.

Thread Thread
aleksikauppila profile image
Aleksi Kauppila

Ah, now i see. Yes, this is incredibly bad practice.

PSR-4 autoloading with Composer is really the only sensible way to deal with imports. There should only be a couple of script files in a project that are not classes. Maybe some bootstrapping script if vendor/autoload.php doesn't cut it and a front controller. Most frameworks also ship some sort of console script to run different commands. That should be enough.

There should be no need for require()s or include()s in other parts of the application.

Collapse
moopet profile image
Ben Sinclair

Of course, there's nothing stopping you from using a variable as a function name and then calling it.

Collapse
markszymik profile image
Mark Szymik

you need $ anytime you call a variable.
you need 2 chars for method calls "->" or "::".

seriously...?

Collapse
itsdarrylnorris profile image
Darryl Norris

I was thinking the same thing. I heard many JS devs saying the same thing.

Collapse
moopet profile image
Ben Sinclair

I'm not sure if you're replying because you think it's a weak argument against PHP or if it's because you're incredulous that you need such things.

Thread Thread
markszymik profile image
Mark Szymik

it's a weak argument against PHP

Thread Thread
lucafabbri profile image
lucafabbri

Just make the some project in PHP, in C#, Java and Node.JS and let us know

Thread Thread
markszymik profile image
Mark Szymik

Let you know what?