Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Had a class of 2.5 k lines of crap like this ....
Brain needs wipe. Beer solution is!
Me Yoda is! -
Cool. You just gave me a headache. Thank you.
This code is a weapon impairing anyone's attempting to read it sanity. Why would you post it without a disclaimer? Why? WHY???
Fuck it hurts -
I really don't know... But I Hope the author of such code never get's access to an keyboard again.
Parentheses, Types, Naming.... Everythings fucked up.
PHP MD and PHP CS with highlighting..... Well editor looked like a fucking blow torch -
And they are bald enough to cry 'everyone needs 2yrs experience to apply, how do I get it then?' and 'free internship is nonsense, it's just a way to get more working hands for free'
mmmyyyyeeeaaaaahhhhhhhh...... Rriiiigghhhtt.... -
rant1ng45676yIf you ever have to make these kind of checks there's something seriously wrong with the design
That's not a php problem, that's a smelly problem
Just saying -
@rant1ng Was Nothing against PHP... Whoever wrote this thought that PHP's weak typing meant "I can just put whateva variable type the fuck I want wherever I want it"....
As in this case - stuffing an array or string in a function and then "misusing" null to detect whether the array was initialized… Serious braindamage. Seems like he wanted to give hints by appling str | arr as an prefix… Which made it only worse...
Simple (PHP 7.2)
public function foo(array $bla) :array
{
if (empty($bla)) {
return array();
}
….
}
And fixed. I really don't know why some people think that PHP's weak typing translates to "I can Change the variable type whenever I want and ambigous functions are completely okay".... Really… I don't have a fucking clue. But in this legacy Project and database there is really of lot of such shit…
(fixed a few typos, still running low on caffeine) -
@IntrusionCM
Strict types in PHP are wonderful. At some point you might not know what is in a variable — usually where user input is involved.
In my opinion, you should have a bunch of "Validator" classes. That's where some empty/array/string/etc checks are allowed.
Anywhere else, strict types, and type hints on all parameters and return types should be mandatory in your code. -
rant1ng45676y@IntrusionCM
I knew all of that could be fixed simply and elegantly, nice solution man.
would you declare strict_types or not? -
@rant1ng I would certainly use strict types (and type hints) for all new classes, and try to rewrite old classes so they can handle the restriction.
-
@rant1g Depends. Small projects with a total number of files < 500 maybe. Above it depends on the age of the project. If it was written before PHP 5.4 then no.
Reason is that PHP 5.4 removed quite a lot of headache cases (Reference misusage, magic quotes and so on) and PHP 5.3 removed super globals.
A lot of these cases can make even small refactorings troublesome and very frustrating.
For new projects - yes. -
@IntrusionCM If your project is written in PHP 5.x, drop everything and get it working on PHP 7.x.
-
Lol.
I think my company would be very glad if u payed us for refactorings....
Seriously, that's not possible most of the time as the customer does not pay for it.
Related Rants
$arr_x = null;
if((!empty($str_x)) AND ((is_array($str_x) OR is_numeric($str_x)) {
$arr_x = (((is_array($str_x)) ? $str_x : explode('|', $str_x));
}
rant
valium
php
typing