A
A
Alexey2020-09-23 13:40:45
IDE
Alexey, 2020-09-23 13:40:45

Kick. The employer said that my PHP code is outdated. What exactly are the problems?

Hello. I'm trying to get a job, for the last 10 years I've been programming for my portals, so I didn't bother much with technologies and approaches.

Now I'm trying to get a job Php programmer. The employer asked to send the code, sent his old one, received such a response:

"There are several points that are unacceptable, for example, error suppression, and generally similar to WordPress 2, etc.."

The class can be viewed here: https://github.com/alex- verem/turcalendar-sample-code

By the way, when I started the project 10 years ago, I looked at what approach to use. It is not excluded that just WordPress parsed ..

My questions

1) What are the main errors / shortcomings in the code?
2) What are the current standards? What project/code to look at to understand the modern approach? Probably suggest something from the frameworks. I would like something simpler to start with.

Thank you!

Answer the question

In order to leave comments, you need to log in

8 answer(s)
F
Foo Bar, 2015-11-18
@atomheart

https://packagecontrol.io/packages/FileTemplates
You can create your own the same way.

S
Stalker_RED, 2020-09-23
@Allexio

@mysql_query()this piece alone is enough to strongly doubt the skills.
The mysql_query function was deprecated over seven years ago and is not present in modern versions of the language at all.
Error suppression via @ is generally a masterpiece. It means that you have a request with an error, or the database has fallen - but your code simply ignores this and pretends that this is how it should be. Get over it :)
Read https://phptherightway.com/

F
FanatPHP, 2020-09-23
@FanatPHP

In general, yes, at first glance, this code makes a terrible impression
It’s not even the 2010s, it’s more like the 1990s
Points
- the constructor that matches the class name is no longer in the language
- a meaningless db variable is passed to the constructor, which is not used anywhere
- functions of the formField() type - this is clearly some kind of hell and injections
- they already talked about mysql_query - they already said
about the dog. moreover, it is not needed here, mysql_query practically does not produce errors
- die ( mysql_error () ); - it's a total mess. By the way, I once saw the result of a similar code on a toaster many years ago, hehe. On a production site, system error messages nevershould not be displayed in the browser. In general, this is a generic mistake of swindlers, which has survived to this day - they have all the errors without fail processed here and now. While the application code should only throw an error, all errors should be handled centrally, elsewhere.
However, there is also good.
The class itself is not bad, and quite competent OOP in general.
perhaps, it is only necessary to correct the syntax, and use some meaningful $db object so that the query is executed somehow like this

function addPlace($place) {
    $query = "INSERT INTO place
        (name,english, countryID, globalRatingID, typeID, worldPartID, datecreated,
        datelastmodified,datepublished,permissionLevel,tansliterated)
        VALUES (
        (:name,:english, :countryID, :globalRatingID, :typeID, :worldPartID, now(),now(),
        now(),:permissionLevel,:tansliterated)";
    $this->db->query($query, [
        'name' => $place->getName(),
        'english' =>$place->getEnglish(),
        // и так далее, всё массивом
    ]);
    return true;
}

N
Northern Lights, 2020-09-23
@php666

die(mysql_error());
programming for the last 10 years
on the programmer zone with no internet?
In fact, lagged behind so much that you can safely look for another job. More precisely, he did not lag behind, and did not even go beyond the beginner.
Seriously, look for another job. Young boys will simply tear you apart.

G
ggrachdev, 2020-09-23
@ggrachdev

Use namespaces, put classes in separate folders corresponding to their responsibilities, read about PSR.
Read about SOLID.
Use some framework on MVC, connect a class autoloader, or you can roll out a self-signature without a framework using libraries like https://github.com/klein/klein.php + plug in a template engine + ORM for working with the database, put the project config in a separate file, select a folder for tests

A
Alex Wells, 2020-09-23
@Alex_Wells

In short, this code is thrown out and replaced with an ORM like Cycle, Eloquent or Doctrine.
And so - there is nothing more to say, the code is garbage on all fronts. Executions, function naming, typing, autoloading - it's all a must for modern PHP development, and you don't have it.

L
Lone Ice, 2020-09-24
@daemonhk

As for me, the main disadvantage is the need to enumerate fields in the class! That is, there is no conditional "model" that would contain the fields and their types, so that each time you do not climb into the class and edit the code in 3 places. In addition, I would take requests into some kind of general function that only deals with requests (sorry for the tautology).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question