r/PHP • • Dec 23 '20

I'm a 12 year experienced PHP Developer. Today I discovered that I don't know how to write PHP

I applied to a PHP job and the interviewer sent me a test as following:

"Write a CRUD application connecting to PostgreSQL, but please don't use full-stack frameworks like Laravel, Symfony or Code Igniter, also don't use Apache or Nginx, just use the built-in PHP server and PostgreSQL, that's it".

Well, seems to be simple, right.

This test is not for a Junior position, it's supposed to be a Senior PHP evaluation, so they are expecting that I will deliver some modern PHP code. I can't just sit down and write some 2005 like PHP script full of includes and procedural.

Before I even think about the CRUD itself, I need to think about folder architecture; a bootstrap/front-controller; a routing component; some kind of basic template system to display standard HTML views; something that at least resembles a ORM or a well organized Data Layer; not to mention basic validations, helpers and of course, unit tests.

I'm kinda lost and the impostor syndrome hit me very hard on this one.

Seems like before attempt to any job interview I'm gonna need to start learning PHP from scratch.

EDIT:

From today on, I decided to call myself a "PHP Framework Driven Developer". I'm definitely not a "Flat PHP Developer", and I'm totally OK with that. Things will be more clear when accept or decline job offers.

Thank you all very much for all the wise words and feedback!

217 Upvotes

261 comments sorted by

11

u/midniteslayr Dec 23 '20

As a Senior dev, who has been using PHP since 1997, I can safely say that this test is BS and not worth the time to put in to it. It wants to test Technical knowledge, but that is something only reserved for mid-level engineers. Senior devs should be asked architectural type questions, as most of the time, you have to consider systems and the impact of those systems on the code base and other systems. This interview sounds like it is for a team that is staffed with a Lead Developer who doesn’t like to delegate, and is intentionally trying to weed out good and bad talent with the stupid requirements, only leaving somewhat mediocre talent who are easily abused by the lead, paid below average, and are only in the job to add a “Senior” title to their resume.

If I were you OP, I would decline and look elsewhere. Your time is too valuable to spend worrying about the test, that will more than likely result in them passing on you (because you’re too talented) or insult you with a really low pay wage.

3

u/pze127 Dec 23 '20

Thank you very much for reply. Eye opening words.

4

u/DaveInDigital Dec 24 '20

lol as a senior dev myself, you read way too far into it or at the very least are clouded by negative personal experiences which is fair enough when you've worked in the industry as long as we have.

1

u/midniteslayr Dec 26 '20

Eh. In my 15 years of professional work, I’ve interviewed at a gamut of places. All the way from Facebook and Sony to small startups that are no longer around. I’ve been employed by a range of companies from Disney and Epic Games to small time startups. The worst jobs I have had were all ones with arbitrary tests and quizzes, that when you finally sit down to do the work, it’s all the same, and all the test did was nothing more than convince someone to try and value you less. Admittedly, those jobs were also lead by abusive team leads.

In my most prosperous jobs, all I ever had to do was sit down for an hour interview with the team.

In the end, anything that a code sample or test does is provide justification for not hiring someone, or giving them a very lowball offer. It also creates a toxic relationship between the company and employee. The company now knows it can make unrealistic demands of their employee, and the employee will more than likely submit to the demands because they will be reminded of the demotivating job search from before.

Finally, from the employer’s side, employment testing is a complete waste of resources, from administrating the test to grading the test. It won’t help shortcut the 100 hour ramp up time a senior dev will need when getting in to the code base. And employers won’t find out about bad habits until about 3 months on the job, so, testing won’t help for anything.

4

u/trideout Dec 24 '20

I can't upvote this more. This is a waste of your time and you should tell them so. I was asked to do a similar exercise recently and only months later realized that I did 20 hrs of bullshit because HR doesn't know what programming is. "Do it from scratch" is for stupid interview questions like binary tree sorting, not a complete application. We are where we are in PHP because we stand on the shoulders of giants.

1

u/midniteslayr Dec 26 '20

“Do it from scratch” or my favorite “Limit the number of packages you use” asks are the worst because they are intentionally ignoring the millions of test-covered lines of code that is completely free to use. Choosing to use “bespoke” in-house code that is 10% test covered and released with prayers, is just plain stupid and a magnet for tech debt.

It also makes me seriously question if the company is wasting things elsewhere.

1

u/smnfms Dec 28 '20

It also makes me seriously question if the company is wasting things elsewhere.

They are interviewing new accountants, but they're not allowed to use Excel or a calculator.

5

u/[deleted] Dec 24 '20

Yup. Lots of comments here saying "you should be able to do this as a senior dev!" And... yeah, ok, you should be capable of it. You shouldn't need to actually do it as an unpaid assignment, prior to even getting a stage 1 interview in order to decide if this place is even somewhere you seriously envisage yourself working. That's just a piss take imo.

4

u/Saphyel Dec 23 '20 edited Dec 25 '20

100% on this, if I get this test I'd say GL. Usually when they say no FW, build a project, etc.. it's a waste of time.

2

u/DreadCoder Dec 24 '20

I have found throughout the years that the software tests you are given ALWAYS reflects company culture.

You dodged a bullet here.

This is the kind of test you would give to a junior/medior position. Either they have NO IDEA how to assess people (which will come back to haunt you when anything regarding compensation is involved) or their priorities are DISTURBINGLY misaligned.

2

u/pze127 Dec 24 '20

I declined the offer this morning. I'm somehow relieved. This thread brought me many insights and reflections about my career path.

2

u/DreadCoder Dec 24 '20

I hope you find what you're looking for soon, it took me several months but i got there.

Happy holidays.

1

u/secretvrdev Dec 24 '20

What would a senior test look like? Please make an example

1

u/DreadCoder Dec 24 '20

For a senior you would care much more for slightly advanced concepts and how they architect their code, using SOLID principles.

Recent example i got hired on 6 weeks ago is they wanted me to write and implementation of HMAC token hashing, and connect to their JSON REST API with it given a set of test credentials, and then display said content in a very basic website of my own that uses no DB whatsoever.

The basics of this is a reasonable ask for a medior if you want to see IF they can do it. But the test here is HOW i would do it. Architecture. Especially when you ARE using a framework like Laravel, because there are a hundred ways you can make a mess of Laravel, it lets you get away with a lot.

Any company still asking IF questions is not really looking for a Senior, unless the technology is really obscure. PHP web applications are not.

TL;DR - IF tests separate juniors from mediors, HOW tests separate mediors from seniors

If you see people using HOW tests on Juniors, that just means they have no coaching and intend to let you struggle without supervision.

1

u/secretvrdev Dec 24 '20

Recent example i got hired on 6 weeks ago is they wanted me to write and implementation of HMAC token hashing, and connect to their JSON REST API with it given a set of test credentials, and then display said content in a very basic website of my own that uses no DB whatsoever.

Junior stuff. This is what a junior is expected todo on a daily basis when implementing wordpress plugins for an Integration.

If you let a senior setup a crud application you can see how he is gonna do it. It doesnt have to be perfect but atleast he has todo some stuff on they own. Doing some hmac auth against a predefined api? noooope.

1

u/DreadCoder Dec 24 '20

yeah, like i said, you can ask lower-tiered people to DO it, but the difference is in HOW you do it.

You could make a fugly hack where the Request has that stuff inserted through an extension of the constructor and a private function, but in Laravel you could do it a little cleaner through Middleware. That's just one example ofcourse

→ More replies (2)

1

u/smigot Dec 24 '20

You find out a lot quicker what kind of developer someone is when you take away their crutch.

No one should be incapable of writing the simplest possible solution to solve a problem.

2

u/DreadCoder Dec 24 '20

Sure, but you're still filtering for the wrong experience level that way.

If you seriously doubt someone with 5+ years on their CV can set up a basic SQL connection, then you shouldn't be hiring them in the first place. And as i said earlier, it reflects the misaligned priorities and/or distrust in the company.

I've done tests too where they ask you to only use the bare minimum, and then turn around complaining it wasn't SOLID enough. Yeah fucker, that's what you asked me not to do. I'm not going to write a Dependency Injection Container from scratch just to satisfy your dumb CRUD take-home.

1

u/smigot Dec 24 '20

1

u/DreadCoder Dec 24 '20

That autoloader does not, in fact, auto-load. undefined datatypes when composing SQL queries leading to SQL injection vulnerability DESPITE using prepared statements, and generally inconsistency in defining (or not) of the datatypes. Complete lack of return type definitions. Single character function names.

But it perfectly proves my point that the HOW is more important than checking IF someone can hack something together.

→ More replies (1)

2

u/lexi_berkman Dec 24 '20

My idiot brain just read, “12-year-old, experienced PHP developer” as the title. I was freaking out for a sec.

1

u/pze127 Dec 24 '20

LOL, no problem, I'm 39-year-old

233

u/adragons Dec 23 '20 edited Dec 23 '20

You don't need orm/data layer/templating. You're over thinking it. Put the SQL in the models.

For routing just use a big switch statement and GET parameters.

Use php as the templating system.

An interview test like this isn't "show us you can implement the best system" it's a "show us you can write php". Adding things like an ORM are a discussion topic for how you would improve it.

47

u/phpdevster Dec 23 '20

Agreed. Also, don't do work for free. A test like this should not be taking up so much time that you can write the boilerplate for a whole new framework while doing it. If the interviewer expects you to spend a full day working on it, then you have a right to be paid, and if they're going to be weird about this during the interview phase, then it's a red flag they expect more than they compensate for.

That means this test is rapid fire, quick and dirty, do whatever you can cobble together only the critical path code necessary to get data from a DB to the browser, and vice verse.

Snap on the glove, and get proctological with it.

2

u/colshrapnel Dec 24 '20

Absolutely correct! I even wrote half the code needed right here in the comment. I think it's really important to understand how the basic concepts work under the hood (and how surprisingly simple the implementation could be).

Sadly, it seems the OP turned down the offer. In their place, I wouldn't refuse such a challenging possibility.

4

u/SIR_BEEBLEBROX Dec 24 '20 edited Dec 24 '20

I agree that a test shouldn't take up too much time, but I disagree with the rapid fire, quick and dirty approach. I have done alot of interviews for senior developers for the company I work for, and when somebody sends in a quick and dirty approach they are automatically rejected without a second phase.

A code challenge is requested to check alot more things besides technical skill. You can tell somebodies mentality, way of working, how somebody approaches a project, how far they go with abstracting layers, if theire coding style fits the team, etc, etc. The code challenge is a perfect opportunity to show the best side of yourself, and it's the place to show all your knowledge about development. (I don't mean the syntax, I mean principles, best practices, design patterns, pragmatic thinking, etc). Based on the effort you can see what a person finds important and where he is most comfortable. If you go about this quick and dirty you are totally not showing your capabilities. (And in my opinion this is alot more important that the hard skills). Also it feels like you don't really want the job. I'm not only checking if you are a good candidate for the job, I also need to make sure that the job fits you.

Especially for companies with a bigger teams it's really important to make a good selection. You want to find a candidate that fits the team, and hopefully stays for a longer period, because changing teams is very interupting. Adding a new member takes slot of time from all the developers, most of the developers aren't such social creatures so building trust can take months. I need to be sure that a candidate is a good fit for the team and company before letting them join, because the "just see how it goes" is taking an insane amount of resources with a big chance to fail. And this is very painfull for both parties.

You also need to understand that checking the code challenges also takes a lot of time from a senior developer and the IT manager, especially if you are hiring multiple developers at the same time. And if a candidate just sends in a minimal viable project it feels like a big middle finger to the company, but also to your potential team. It's not only the candidate that is spending a lot of time of the job interview process, I'm sure the company puts in more hours in total then the candidate for such a challenge.

I would not recommend this approach if you want the job, at least not in Europe. Put in the effort and show them what you are worth. This doesn't mean that you need to spend a week on the challenge, some companies out some weird challenges but its always possible to ask questions for clarification. The only times we had developers put a lot of time on the challenge was in cases where the candidate didn't read the challenge correctly, or they didn't have the skills yet and spend lots of time learning. We always ask how long somebody spend on our challenge, and when we find out somebody used extra time to learn we see that as a big plus. It shows you are willing to join, learn and improve. Very important qualities which we are actively looking for in every candidate.

TLDR: put in the effort, the code challenge is used to see how you think and what kind of person you are. Not how well you memorized the syntax. If you skip on this, it could be a wrong fit for both parties.

4

u/phpdevster Dec 24 '20 edited Dec 24 '20

A CRUD app where you’re not allowed to use frameworks and what not is not exactly a quick project. If you are given an hour to do it, quick and dirty is literally the only way. I would spend a lot longer than that just building a router or even learning an HTTP library like Symfony’s.

An hour means you’re going to be raw dogging it with $ _GET and $_POST and basic PDO statements. That is quick and dirty no matter how you slice it. You literally will not have time for anything else.

If it’s a longer time period, then it’s a different story. You should take the time to refactor and choose appropriate abstractions.

Also, a good senior dev will know how to balance "make it work" vs "make it good" depending on requirements, time tables, and lifespan of the project. Someone who instantly starts reaching for a solution and requirements that don't exist, and then never delivers on the results because they were too mired in getting a foundation laid out, shows they are not good at balancing requirements, timelines, and architectural approaches yet.

1

u/[deleted] Dec 24 '20

Right on point mate. Otherwise, no one would bother with quick and dirty code. The challenge would be meaningless. It is impossible to implement modular and maintainable code without abstract thinking and object-oriented design skills. OOP is underrated within the PHP developers. However, OOP is how you model the real world problem in the computer.

1

u/aceplayer55 Dec 26 '20

But then the challenge should be: Write your own basic framework from scratch. NOT create a CRUD app without using a framework.

23

u/__radmen Dec 23 '20

This.

I can also tell I'd feel disgusted writing code this way :) On the other hand, this is a good refresher. It reminds me, that you don't always need to use everything you have to achieve a simple thing.

8

u/Nerwesta Dec 24 '20

This.
Exactly what my professor taught me when I was still a student. ( I had to make a simple fullstack app for school )
I'm very grateful to him, that I learnt this way of baking PHP apps, before diving on frameworks, ORMs etc.

6

u/cowboyecosse Dec 23 '20

This is a great answer. I love that OP feels uneasy on this too. I know I did. This comment really helps detangle the thinking behind the question. I’m completely flipped on my original, gut, run Forrest run, answer.

4

u/kross10000 Dec 24 '20

How will that show off your coding and architecture skills? Every monkey can write up some shitty code which "works". Actually I would ask interview questions exactly to separate the people who write code like you suggested from people who are actually able to create maintainable applications and understand how to properly architecture software.

1

u/adragons Dec 24 '20

Having architecture skills is a valid concern, but not so much given the task. What is equally important is knowing what the appropriate tool for the job is, fulfilling the requirements and finishing by due dates. Besides, maybe in that work place the senior developers work under a software architect.

2

u/kross10000 Dec 24 '20

Then maybe the key point is to get back to the interviewer and do some requirement engineering. Especially the timeframe and the expectations on scalability and maintainability. Probably they even deliberately gave almost no specifications to see how the candidate will communicate?

If they say you have one hour and it will be a throwaway-project, then fine, they get the requested single php file CRUD "application". But in that case I'd still argue that this wouldn't prove any skills which are relevant for a 12-year senior programmer.

1

u/adragons Dec 24 '20

The brief does seem to lack any details. But to me it almost seems like the OP fell right into a trap of applying "how it should be" rather than "what was asked".

If you ask for your steak well-done and you get a medium-rare even though Gordon Ramsay, nay everyone knows medium rare is how it should be, you still shouldn't accept it.

3

u/spin81 Dec 24 '20

This exactly. This really feels like a FizzBuzz test. So you can copy paste Laravel tutorials but bro do you even PDO?

2

u/DaveInDigital Dec 24 '20

yeah PDO feels like the obvious answer; why would you need a full framework implementation for a quick and dirty CRUD test.

7

u/aallport Dec 23 '20

Hate to hijack, but had something similar when getting into the industry. It's worth noting that it says you can't use a full stack framework, doesn't say anything about libraries.

When I did my challenge, I used SlimPhp. There's enough there that it allows you to demonstrate good OOP. I then went down the route of writing a repository like class to handle the IO.

I believe I used twig to allow separation of the front-end

Upon review they were very impressed with the way I had structured the application, especially given my lack of formal experience. They also mentioned that they have had people apply to be a senior with a worse application.

That's just my £0.02, but hope it helps!

2

u/SIR_BEEBLEBROX Dec 24 '20

Exactly, you don't need those tools at all. But it's good to mention that in the PHP world there are different levels of environments nowadays.

You have you standaard monolithic applications, which most of the time use a full framework like laravel or symfony. In this scenario it's perfectly fine to use frameworks, orms, etc. They are optimised for that kind of environment.

But when you want to build a scalable application based with microservice all the best practices we are used too are suddenly not fitting anymore. Microservices are lean and light, ORMs are heavy and complex. Its hard to include an ORM on 5 microservices that access the same data, I don't say it's not possible, it just brings alot of issues that you won't face in a traditional monolithic applications. And not to mention version management of all the frameworks/libraries across 50+ services. Also frameworks lock you in to a specific way of working. With microservices you can run PHP, java and go services along side eachother without issue, but streamlining the communication across all the microservices requires custom implementation. There are simply no best practices for each combination of languages and usages in a micro-service environment.

Besides I haven't seen yet an ORM that is really performant, we have found that we don't need an ORM at all if you allign your models with the data source. Sure it's nice to auto generate sql, but most of the time the SQL that comes out of an ORM is not optimised at all.

1

u/adragons Dec 24 '20

Good point. I wasn't even thinking about scopes beyond "normal apps".

0

u/[deleted] Dec 24 '20

I won't give a penny to someone who uses a switch in routing. Have you ever heard of cyclomatic complexity? Yeah boy, you won't be last by writing such conditionals.

For the routing, I expect at least something like "URI" => Controller::class array and factory for each controller. Why? Because I expect the candidate to utilize some design patterns as well as presenting some SOLID approach. And I'm sure that the recruiter thinks exactly like me so they wanted it in pure PHP.

1

u/adragons Dec 24 '20

Do you check if the URI to class mapping exists? Wait, "if"... Oh no!

1

u/[deleted] Dec 24 '20

This doesn't have to be if. Just go for it. Then catch the exception and show 404. Plus: one or two ifs are okay.

→ More replies (7)

66

u/[deleted] Dec 23 '20

Not to make you feel too good about yourself, but the fact that you can list out p much all the considerations you’ll need means you’re probably not an imposter.

the fact that you can’t barf a crud app without googling a little means you haven’t been doing speed coding competitions lately.

15

u/StrongStuffMondays Dec 24 '20

I write PHP almost daily for last 17 years, but I still cannot memorize order of arguments in strpos() function

5

u/pfsalter Dec 24 '20

Just write strpos(needle: 'f', haystack: 'foo'); in PHP8 :)

1

u/secretvrdev Dec 24 '20

Then go to the docs or use PHPStorm. Its not that hard.

2

u/StrongStuffMondays Dec 24 '20

My point was that some "googling" is still required for very basic kind of PHP-related tasks

→ More replies (1)

0

u/[deleted] Dec 24 '20

[deleted] — view deleted comment

3

u/DreadCoder Dec 24 '20

mind blown, i never noticed there was a pattern, just thought it was inconsistent.

It looks like you are right: http://phpsadness.com/sad/9

2

u/pfsalter Dec 24 '20

The problem is quite a few of the array_ functions take multiple arrays, so it's often $callback, ...$arrays, which I think helps with the confusion there.

7

u/[deleted] Dec 24 '20

I can code in C++, C, PHP, Javascript, Typescript, Python and even Lua, at the beginning I always felt bad for not being able to code without Google, nowadays? I just copy and paste, every company I've work for has been completely happy with my results, one day I was even hired by a grumpy guy who was tired of hiring "chinese and indians who had issues communicating and couldn't deliver the job properly", all of them passed the tests, when he spoke to me he just went on because finally he could understand a good english from a foreigner and I just started working right away without even doing an "interview" or a "test", I used Google since the first day, when I left the company, a month later the guy asked me if I wanted to work with him again, and I can tell you right know, I DO NOT KNOW any of the languages I posted above from memory, none of them, I know what the funcion names may be, but if I'm trying to connect to a mysql db in c++ I just type "c++ mysql lib connector cheatsheet/documentation", nobody really needs those "speed coding", a lot of companies nowadays want to hire idiots this way, like if that really translated into success, most indians I've seen always "code fast", yet their code is filled with bugs, errors, run slow, is unreadable, in fact, whenever my internet goes down I just "stop coding" because I know I use Google for pretty much a lot of functions, I even had to install ZealDocs because of this

28

u/Salamok Dec 23 '20 edited Dec 23 '20

I'd probably use a simple templating class, rough in some common codebase (bootstrap/global functions/config) and a simple front-controller, skip the pretty url router, caching and more complex stuff (but think about how you might approach those). I think you are over thinking it, they dont want a production quality application they just want to see some code. When you do the walk through touch on how you might improve the application if given more time (add routing, caching, etc...).

Remember they just asked you to write an application that adds, updates and deletes records in a database. They didn't ask you to come up with a full featured framework. Keep the code clean and simple, be sure to use PDO and not have any glaring security flaws in your SQL. Keep in mind they may red flag too much procedural code so steer things in an OOP direction.

edit - To each their own but I far prefer interviews where they give me a few days to write something that becomes the MAIN discussion topic of the in person interview. I always walk into these interviews prepared because hey we are gonna talk about "my code" and "my approach" this is infinitely better than being hit with a barrage of brain teasers that seem to exist only to prove how clever the interviewer is.

11

u/jitendracshah Dec 23 '20

I am on opposite side, I use it starting from 2010,can work on modern vanilla PHP, But I cannot get myself deep in frameworks, I kinda not like that too much abstractions.

and I just accepted it, when I need to use framework I just Google it and make short term memory of it and later forget all.

6

u/moob9 Dec 23 '20

Same here. Started dabbling in 2000, never used a single framework and I have been employed for almost all of these last 20 years as a full-stack developer.

I seriously don't understand why someone would require the use of frameworks.

4

u/[deleted] Dec 24 '20

Just depends where you work. I’ve been at places where there were developers who had been at the company for ten years or more. That amazes me, because on one hand, good for you for staying at one place for so long. But on the other, you have severely been held back and haven’t really grown. They can “use” a framework but their code quite clearly reflects that they don’t know the framework, so everything they write has to be refactored (like why use cURL to make requests when you have an HTTP client that does it already and has exceptions and everything else).

As for why use a framework? I can use this guy as an example again. Because he had worked at the company for so long, there were lots of legacy projects sitting around that ran on PHP 4 and 5. He had worked on these too. They weren’t using frameworks. For security reasons and maintainability (because people who hadn’t been there for a decade had to make changes), it made more sense to get everything on a single framework rather than try to perform the impossible task of knowledge transfer or learned quirks of the code base. The code was so mangled and led you on down the proverbial rabbit hole every time you had to touch it, that he was pretty much the only one who could fix shit on it (we could have too, but not as fast).

Once everything was on a unified framework, the legacy projects now could have anyone add unit and feature tests, keep it upgraded, and not reinvent the wheel if we wanted to add a new feature. There was a coding standard again, and you put files in a conventional place, not whatever felt good at the time. CI/CD and Docker for local development were also easier because you could use a single template or pull in the Docker repo and didn’t need a one-off hodgepodge.

Those “it takes everyone 5 hours to do what it takes this guy, and only this guy, to do in 1 hour” add up. 20 hours a week at the going rate times 52 is a lot of money. Consistency, speed, and onboarding are major bonuses because I don’t have to document how my non-framework project works. Or worry so much about security issues. Any developer can work on it and understand it or get help from hundreds of thousands of other people, not just “that one guy who had been here for over a decade.”

There’s only been one place I worked where a framework wasn’t used. Never again. You feel like you stepped back into the early 2000s and everyone else is passing you by.

1

u/moob9 Dec 24 '20 edited Dec 24 '20

That's weird and not at all like my experience. It sounds like your example is someone who doesn't really know how to code at all and using frameworks wouldn't help in their situation.

Like, let's say two different people made the same project in PHP. One of them used Symfony, the other didn't use any kind of framework. If they both are proficient programmers, anyone can read and understand their code. If the Symfony developer sucks, a framework doesn't help anyone read their shitty code.

Not once during these last 20 years have I heard anyone complain about my code.

1

u/jitendracshah Dec 24 '20

Yes. for small projects, I mostly do same with packages of stateless functions and OOP Entity model I borrowed from my C# experience. Everything is well documented, never had any issue with approach.

in fact, my first project was my college website which I built in 2010, Its still up and running on same codebase, with minor updates. It was not as clean and document as I work now but a fairly solid for a student.

1

u/[deleted] Dec 24 '20

If I just had to read one developer’s code, that wouldn’t be a problem. Wanna guess how many people over 10+ years have touched a single code base?

1

u/moob9 Dec 24 '20

It also wouldn't be a problem if every single one of them knew what they were doing.

Right now we have a 12 year old code base that started on PHP5 and we are currently upgrading it to PHP8. It's clean, well documented, we use PSR etc. I don't really understand what benefit would a framework have here.

2

u/[deleted] Dec 24 '20

Well, congratulations then for working at the only company who has somehow managed to only hire competent developers for more than 10 years who document, test, and adhere to standards, while also being able to bring on new developers who can quickly work on something completely new.

1

u/jitendracshah Dec 24 '20

Sounds like a need of complete rewrite of system due to old tech debts.

+1 for pointing the self-growing point.

1

u/jitendracshah Dec 23 '20

I think for me its because I can code in multiple languages like Java(for android), c#, python, php, c/c++, javascript and currently learning Go and Rust. I can comfortably use all of them in vanilla state, but not frameworks that is why I am weak with node.js.

I just don't uses frameworks unless required. I have made my primary style of using stateless functions mostly. Its just addictive.

2

u/[deleted] Dec 24 '20

What’s funny about that is, knowing frameworks makes it easy to work in other languages too because all frameworks are very similar. Do you know Laravel? Look at Adonis then for Node. You won’t feel out of place at all with Blade-like templates, seeders, migrations, and factories. It’s an entirely different language but feels 100% like what you already know.

1

u/pze127 Dec 25 '20

That's why when I was requested to jump from Laravel to work on a Rails project I managed to grasp it in 10 days without been ever touched Ruby before. I couldn't imagine doing that being a vanilla PHP developer.

1

u/jitendracshah Dec 24 '20

I don't feel out of place, I just don't like them.I have used Laravel, CI for PHP and Express for Node. They just works!! but I dont know why and how until I see their core source code!

2

u/kimk2 Dec 23 '20

Same here, back from the days when bookstores didn't know what PHP3 was :)

1

u/Alexell Dec 24 '20

You've probably ruled it out, but in case not, try symfony. You're very often only 1-2 abstracted methods away from bare PHP. Many times you click on a method to view it and it's plain PHP.

Once you get into the derivatives like Sylius, then it becomes really abstraction heavy but that's true for any framework.

4.* and 5.* now ship with nothing but the bare minimum by default.

1

u/jitendracshah Dec 24 '20

yes agree. Symfony is a great choice if I want to do some standard operations with bare minimum dependencies.

13

u/Tiquortoo Dec 23 '20

Is that the complete spec? In that case you need none of that. I read these requirements as "Write a simple app, not a modern one, do it barebones." They didn't ask for folder architecture, bootstraps, routing, templates, views, controllers or anything. They kicked the crutch out from under you and said "Dance!" So... just do it.

It might just be that the first test of this test is: Does the person have a habit of inventing, or not asking for refinement of, requirements. Which is a pretty key skill for a Sr. dev.

7

u/missitnoonan78 Dec 23 '20

Why? What exactly is this testing and why is it practical knowledge in 2020? This is the type of nonsensical busy work that drives me crazy in an interview.

3

u/pze127 Dec 23 '20

They know I can probably ship a Laravel CRUD in half an hour. I kind of agree that is unfair from the interviewer point of view. They just want proof that I can deliver good quality PHP code. But it's crazy haha.

7

u/missitnoonan78 Dec 23 '20

That's why I'd rather see something like code review, refactoring old code, or writing some tests. No one would start a greenfield project in this way, so why ask someone to show they can?

Honestly I'd rather see someone push back and ask question about the assignment, like what can I use, because starting routing from scratch seems ridiculous.

34

u/devmor Dec 23 '20 edited Dec 23 '20

Any modern PHP developer should be able to do this with no sweat. This is not a huge ask, nor is it technically complicated - but it is core knowledge.

If the candidate can't demonstrate that they understand how the underlying stack works, how they be trusted to write good code abstracted one level away from it?

Will they waste hours or days looking for a solution when they encounter a use-case that the ORM doesn't handle? Will they be able to transition routing solutions if a front-end changes from templates to an SPA? Can they recognize and mitigate security issues that a framework may get wrong in handling?

Far too many developers are utterly useless outside of their chosen framework/ecosystem. This is why companies end up with 3 interviews out of 1500 resumes.

1

u/mibu31 Jan 03 '21

+ this!

5

u/freexe Dec 23 '20

You can still use doctrine, package managers and Symfony libraries to do most of the work. It would show you know the principles behind the framework and it's not much extra work.

-3

u/oojacoboo Dec 23 '20

Bullshit. Anyone with a real product needs this knowledge in their organization.

12

u/colshrapnel Dec 24 '20 edited Dec 24 '20

Yes, you need to learn how all these things work. Actually basic versions are no more than a dozen lines of code:

  • the folder architecture simply follows namespaces.
  • PSR-4 autoloader is even less

      spl_autoload_register(function ($className) {
          $ds = DIRECTORY_SEPARATOR;
          $className = str_replace('\\', $ds, $className);
          $filename = __DIR__ . "{$ds}..{$ds}src{$ds}$className.php";
          require $filename;
      });
  • router, is a simple switch case given you are using GET parameters or if you want to make it a bit fancy, then use the router parameter for the built-in web-server which will redirect all requests to your router file where some basic string parsing is involved and then the same switch case.
  • basic templater again is half a dozen lines,

      function template($file, array $data = []) {
          ob_start();
          extract($data);
          require __DIR__ .'/templates/' . $file;
          return ob_get_clean();
      }
      function e($value) {
          return htmlspecialchars($value, ENT_QUOTES)
      }
  • basic validations are built-in, like email or integer validations (see filter_input()). For strings you can write your own.

For the CRUD itself you can choose between two approaches: it could be a blunt one-entity CRUD where you are writing direct SQL; or you can create a basic abstract ORM, or a TableGateway, like this

abstract class BasicTableGateway
{
    protected $db;
    protected $table;
    protected $fields;

    public function __construct(\PDO $db)
    {
        $this->db = $db;
    }
    public function read($id)
    {
        $sql = "SELECT * FROM `$this->table` WHERE id = ?";
        $stmt = $this->db->prepare($sql);
        $stmt->execute([$id]);
        return $stmt->fetch();
    }
    public function update($data, $id)
    {
        $params = [];
        $set = "";
        foreach($data as $key => $value)
        {
            if (!array_key_exists($key, $this->fields)) {
                throw new \InvalidArgumentException("Unknown field");
            }
            $set .= "`$key` = ?,";
            $params[] = $value;
        }
        $set = rtrim($set, ",");
        $params[] = $id;
        $sql = "UPDATE `{$this->table}` SET $set WHERE id=?";
        $this->db->prepare($sql)->execute($params);
    }
}

and then just bang in the Create, Delete and List

Then it can be used like

class TaskGateway extends BasicTableGateway
{
    protected $table = "tasks";
    protected $fields = ['task_name', 'start_date', 'completed_date'];
}
$taskGateway = new TaskGateway;
$task = $taskGateway->read($id);

you see, it's not much a code to write

3

u/smigot Dec 24 '20

In my opinion this is the right solution and what they would be looking for.

The framework of a framework, if you will. The simplest framework that solves the problem at hand, with all the foundations for extension when necessary.

2

u/helloiamsomeone Dec 25 '20 edited Dec 25 '20

I actually pieced something like this together in a few hours to run on my GCE a year ago. Turned out to be an overkill and now most of the code is just running on a cron job pushing data elsewhere.

My router class as an example: https://hatebin.com/jrjuwqawqb

2

u/hktr92 Dec 26 '20

...or take my "auto-routing" implementation: https://hatebin.com/dwtdtrzlok

this will interpret GET /hello?name=foo" as src/Action/Hello::get(), or POST /auth/login as src/Action/Auth/Login::post().

It would be nice to automatically bind route parameters as method variables (e.g. GET /hello/{name} => src/Action/Hello::get(string $name) but I didn't have time for it, although it would be simple to do so, again, I didn't have time for it).

1

u/helloiamsomeone Dec 26 '20

I don't understand where $this->routes on line 34 is supposed to come from in a final class with no fields. I would prefer $response = \Closure::fromCallable([$instance, $action])(); too.

54

u/Fit4BJJ_Pat Dec 23 '20

That doesn't sound that hard to me? A senior should be able to handle it.

You don't need an ORM. You don't need a template system, PHP has one built in already. They are not asking you to write production code, just to see if you can handle writing code without a framework.

If you are completely lost without a framework then maybe you should not call yourself a senior PHP developer. Maybe a senior X framework dev, but not PHP.

Maybe this will helps (although it uses components): https://github.com/PatrickLouys/no-framework-tutorial

-7

u/sinnerou Dec 23 '20 edited Dec 23 '20

Have to disagree. Any interview requiring obscure, arcane, or specific knowledge is not testing a candidates ability as a developer. There are plenty of ways access someone's developer chops outside of a framework that do not require specific knowledge or even a specific language.

A question that is this specific is just rolling the dice of whether on not the candidate has worked in this specific area recently or has a specific interest.

Edit: just reread and realized this may have been a take-home. If this is a take-home then it is more reasonable, a developer should have the resources to find what they need along with their expertise to make a reasonable attempt. But it is still awfully specific knowledge and will favor candidates who have dealt with similar challenges recently.

If this is in interview, synchronous, then I would say it is too obscure and is just a diceroll filter. If it is a take-home it's way to broadly scoped, there needs to be significant clarification of the requirements.

5

u/Firehed Dec 23 '20

I don't think this is a great interview question even as a take-home, but it's not entirely unreasonable. It really depends what they're looking to get out of it and what sort of expectations they set before the prompt.

2

u/sinnerou Dec 23 '20

Right, I don't think the expectations are clear if this is a take-home. I favor "first day on the job" sort of questions over arcane knowledge or brain teasers, the latter are being artificial filters. This is not good on several levels imo.

8

u/andrewfenn Dec 24 '20

Not using a PHP framework is not obscure, arcane or specific knowledge. This is a ridiculous perspective to have.

0

u/sinnerou Dec 24 '20 edited Dec 24 '20

Building routing layer from scratch is academic and in no way used on a day to day basis. Just as quicksort and merge sort are acedemic and built in to nearly every language.

While everyone learns these things they have been thoroughly abstracted and are so readily available that the necessity of retaining the specifics has long since passed. It in no way indicates your competence as a developer that you happen to have that knowledge readily available and only indicates that you happen to have a specific interest in that specific topic.

Also, it is possible to disagree and have a dialog without being rude and condescending.

2

u/secretvrdev Dec 24 '20

Building routing layer from scratch is academic

I dont think it has to be performant. Its just a test task. Whip up the basic routing you can do. Takes me 15 minutes.

1

u/sinnerou Dec 24 '20

Here is a dialog I can get behind. I think we are now assuming we know the mind of the interviewer. OP clearly thinks that he has to be more rigerous. To me that says this task is unclear in scope and expectation which means the candidate is not going to demonstrate their best self and the interviewer isn't going to get good signal from this challenge.

When I was developing php fastroute was pretty standard and was used by slim amoung other frameworks, can it just be installed? Idk.

To me OP sounds competent, they have 12 years of experience and pretty succinctly laid out what would be required for a modern mvc framework in broad strokes. We are a just guessing, but my guess is calling OP "not a php developer" is far off the mark.

→ More replies (1)

3

u/andrewfenn Dec 24 '20

My understanding from the task is that they don't need to build a router layer from scratch. Not using a framework doesn't mean you can't use libraries. If you can't even use libraries and composer then I'd agree with you, but that's not what is stated. You can easily put something together using a few libraries and composer.

I stand by what I said. Clearly this test is over the top but also calling writing normal PHP code obscure or arcane is ridiculous. Clearly the bar of PHP development in here is set too low if anyone ends up actually upvoting this opinion.

→ More replies (7)

21

u/systemadvisory Dec 23 '20 edited Dec 23 '20

Just use include to include php files, use inline php for templating. Use PDO for db queries. Use GET paramater 'a' or something to show what action to use. Don't over-engineer it, it seems like they wouldn't like that. Here's a model I would start with:

https://pastebin.com/r6zhGC9h

21

u/kingdomcome50 Dec 23 '20

I’m going to be honest. I had that entire project written in my head within seconds of reading the prompt. This is exactly the kind of question I would ask to weed out people who don’t know how to solve problems.

The above shows that you know how to program, and that you know how to organize a system without leaning on a crutch like a modern framework to handle all of the details. This is really important because none interesting problems out there come with a framework in how to solve them. Believe it or not, most business problems aren’t “make a small CRUD app” and sometimes require some actual engineering to solve them.

It sounds harsh (and I expect some backlash), but maybe you aren’t a senior developer. Years don’t necessarily equate to aptitude. I saw this quote on HN the other day and I think it would help give you some food for thought:

Write code. Not too much. Mostly functions.

4

u/ihugyou Dec 24 '20

You can tell OP was trained with a framework by the things he listed he would need to think about for the assignment, even though it sort of asked to avoid those things.

To be frank and personally, weeding people based on someone not knowing how to write a crude CRUD app seems really like a pet peeve. You don’t need to know how to include straight up PHP scripts to do some inserts and selects these days to be a senior PHP dev. I just don’t think I can make a strong link between knowing that kind of stuff to solving “engineering” problems (really mostly business problems) with PHP.

2

u/kingdomcome50 Dec 24 '20

Look, reading it back maybe my intentions were a bit obfuscated by my momentary contempt for the idea that someone who could call themselves an experienced PHP developer wouldn’t be able to bootstrap a simple CRUD app without guidance. It really comes down to what “senior developer” means to your organization.

For me it’s less about your ability to produce systems and more about your ability to guide, develop, and otherwise multiply the development of your peers. If you don’t know how to include a PHP file... are you going to be able to implement a Hungarian Matching algorithm (I’ve actually had to do this!)

I can honestly say that every single junior developer on my team would be able to finish the prompt above with no help at all. From the database all the way up to the UI (SQL to CSS). Maybe that is a reflection of my own ability to lead and develop my team. Or, more likely, it’s just a disappointing reflection of the current state of programming in general...

1

u/ihugyou Dec 24 '20

I actually understand what you’re saying and your intentions. Definition of a “senior PHP” dev is really dependent on the organization. The level of experience and knowledge really varies a ton depending on the team. I think having a high standard and being able to find talent to meet that is great! It’s been hard for my team to find truly senior talent with the right set of knowledge, and I’ve given up expecting senior candidates to know everything I expect them to know.

5

u/hktr92 Dec 26 '20

This is a paradox I've encountered too. We are so used to work with frameworks that when we have to use vanilla PHP, we either reinvent a framework (like I did with a uni project) or bang our heads against the wall that we don't know vanilla php.

same feeling I had when I did that uni project. I ended up writing a minimalist PHP framework that did the routing automatically for me depending on request method. Yes, I'm a lazy person and I'm not ashamed to recognize this one. and when a colleague of mine (which don't know anything about PHP, while I'm working for 3 years as a web dev) asked me if this is really necessary I simply replied "meh, it's easier for me to do certain tasks this way, it prevents me to have duplicate code and have direct access of variables".

sure, I could do something like `request_get('name')` where "name" is the param name from $_GET, but meh, having a full-blown `Request` class with stacks felt more natural to me.

and this is somehow weird, because this uni project made me feel like I don't know PHP at all. and the consequence is the usage of PHP frameworks. but the biggest advantage we have is that when we have to write something "from scratch" we already know how to structure and do better this one, creating some sort of "framework" or "app logic" (if you want to name it like this, it's irrelevant the naming) that our app would be developed easier and faster without banging our heads against the wall that we don't know what method x does in framework / library y.

on the other hand, at work, we employed a very talented guy that worked with vanilla php and built-in php framework before. our project was already started with symfony and he found it weird and he "was afraid of symfony" (his exact words). now he's more confident in that framework but he still does have a small fear of the framework, on the principle "i don't want to break it". however, his background helped our project so much that even I changed my vision and coding style in symfony and in php projects in general.

the conclusion is, when you develop php project in frameworks, you forget what php really can do. on the other hand, if you don't use frameworks at all, you are a bit reluctant to use any framework at all as it limits your skills and you tend to do many things to achieve little. so having a balanced experience both vanilla php and a framework would be ideal, but it won't be as easy as one might think it would be. (since I started to work on various php projects, I did something like "for each php project that used a framework, wrote a php framework myself that simplified some of the things a framework did, afterwards learned a framework in other programming language to achieve new knowledge and better understand php".

2

u/phdaemon Dec 23 '20

You could always use a microframework for the MVC part. However, saying don't use frameworks to me is a red flag.

6

u/pze127 Dec 23 '20

They asked this because their projects don't use any open source framework at all. It's an "internal framework". This is a big red flag to me. I'm considering this job because it's a good salary, but I know, once I'm in I'm doomed and will be buried in Frankenstein procedural code haha. I'm evaluating if worth the effort.

5

u/missitnoonan78 Dec 23 '20

Last person I knew in that situation walked into a company still on PHP 5.3 (when 7.1 was current) because their custom framework would be too hard to upgrade.

3

u/StrongStuffMondays Dec 24 '20

I think it would be fair if you will ask them to show you their internal framework or describe it a bit. It may turn out not as bad as it sounds (although chances are not that high). In worst possible case it would be a good story for thedailywtf submission

6

u/phdaemon Dec 23 '20

Run away.

3

u/KFCConspiracy Dec 23 '20

Any time I've ever worked with a client who had an internal framework it's always been a disaster.

1

u/[deleted] Dec 24 '20

Exactly. Any project of sufficient complexity has three options:

  • use an off-the-shelf framework
  • build their own buggy, undocumented, insecure, unusable one
  • use ridiculously expensive developers to build their own good one

4

u/ahmadalmayahi Dec 23 '20

It shouldn’t be that hard. Here are my suggestions:

  1. Use PDO with prepared statements instead of using ORM systems.
  2. Sanitize the inputs by using the filter_input function.
  3. Put your your files in /src and tests in /tests folders.
  4. Use spl_autoload_register instead of composer autoloading.
  5. Create a simple router that reads the page query param and invoke the appropriate function/controller.
  6. Create a very simple class that acts like a container, so you can fetch your services easily.

1

u/S44F4Y4T Dec 24 '20

Btw what is built in php server?i thought it only run on server either apache or nginx

1

u/secretvrdev Dec 23 '20

If your problem is the folder structure youre out. Just stop.... omg why do you call yourself a senior if your have problems with folders.... omg

1

u/pze127 Dec 23 '20

I did not name myself as senior, the JOB post is "seniorish". I know how to scaffold a project tree. I list "folder structure" just to give some context for the task.

1

u/secretvrdev Dec 24 '20

Why do you want to apply to that job when youre not a senior? Makes no sense for me.

1

u/pze127 Dec 25 '20

Because experience level expectation vary from company to company. There's no clear line in software industry for this.

What a small company consider Senior, a similar position on Google could be seen as Trainee.

3

u/brzzzah Dec 23 '20

Is there any reason you can’t use existing packages to compose your own framework? The way I interpret that require its still open to using packages, that’s what I would do. for example I might use php-di, fast-route, (maybe even slim?) cycle or doctrine for data layer, twig for views etc. you can whip up a nice modern app like this quite quickly

3

u/BoneBreakerz Dec 23 '20

Having been on both sides of this exact same question, I can tell you that you are definitely overthinking it by a long shot. The most complex piece here is the C in CRUD, it needs authenticate, and make a connection, so keep security in mind. Then the rest of the functions should take your persistant conn as a parameter, along with the query params, and basically just execute. Keep the functions basic, simple, and to the point, and you will get bonus if you remember to sanitize your queries to prevent injections/xss/etc. That's all they want to see, don't fret about routing, bootstrap, or HTML, they want to see your PHP code and that's it.

Senior Dev's aren't about who can write the most convoluted, abstracted, now only GOD knows how this works code, it's about who can write code that everyone can understand, meets the criteria, and doesn't break when you toss "lizard" as an integer.

1

u/DaveInDigital Dec 24 '20

Senior Dev's aren't about who can write the most convoluted, abstracted, now only GOD knows how this works code, it's about who can write code that everyone can understand, meets the criteria, and doesn't break when you toss "lizard" as an integer.

exactly. i've worked with many who absolutely love to write complicated systems where every time another developer asks how something works, they have to set up a meeting or take a phone call for the senior dev to explain all the nuances of their code and philosophy. i absolutely hate that and have watched a lot of projects fall by the wayside because nobody else wanted to work on them, much less take on those stupid meetings just to add a feature or fix a bug. being a senior isn't about showing everyone how smart you are, it should be about how you build up younger developers and give them the power and confidence to actually make meaningful contributions while you use your experience to help prevent pitfalls they can't see yet. at this point in my career i have a large say in the room so i always tell the Big Brains that everything for a project needs to be simpler and to save the over-abstractions and high barrier of entry for their personal projects. in an ideal world, work should be as simple we can make it and fun/creative; it's a real drag when work is so difficult and complicated that you leave work feeling brain drained and unable to work on any personal projects or dread the next day of work simply because a senior developer needs every step of the way to be a dick measuring contest.

2

u/BoneBreakerz Dec 25 '20

I can't even count how many times in the past 3 months I've had to code something based on theory, and what "should" be sent down the pipe. Sometimes you just have to know how to put it all together. Ya, I dread those "real quick meeting to explain my code" meetings, they are usually worthless.

3

u/sleemanj Dec 24 '20

I'm a 20 year experienced PHP developer, I feel the exact opposite of you.

If given that task I would be in heaven, simple, easy, straight forward, no problem piece of cake.

But ask me to do anything in any of the current frameworks and I feel like a steam engineer dropped into the space program.

1

u/eurosat7 Dec 24 '20

I had the same situation/problem (18yrs professional into php). Then I started to learn how some core parts of symfony are coded IN DETAIL and to think about how other programmers did it and why - this was a good decision for me because I learned a lot of things I was not aware of (look up "dunning kruger effect") and it was entertaining. Side effect: I'm quite solid in symfony now :D

So if you have spare time you might want to take a look. It will speed you up.

3

u/Herbert256 Jan 02 '21

write some 2005 like PHP script full of includes and procedural.

that's still how I use PHP, as a template language without using frameworks or template engines.

PHP did go into the wrong direction, it started when OOP was added, it gets worse every release, 8 is complete nuts.

1

u/painkilla_ Jan 10 '21

what's wrong with being able to write code that adheres to SOLID principles, use interfaces , polymorphism and abstractions?

5

u/stilloriginal Dec 23 '20

Not a pro or anything but you could simply use a repository pattern and write the queries inside that.

2

u/secretvrdev Dec 23 '20

Wait where do you guys write your queries else? Not in a repo? Active Model?!?!?!

3

u/stilloriginal Dec 23 '20 edited Dec 23 '20

uhh I normally just use eloquent and do thingie::where()->get(); type of one liners inside the controller. Anything requiring more than a one liner I put into a "Service" class which generally has one function called get(). For instance ListService::get("company_id"); (pre-formatted for select boxes) or BalanceSheetService::get(12/31/2020), something like that. But again I am NOT A PRO I just figure this stuff out. I use these "services" to clean up my controllers if there is too much logic, or to use the same logic in multiple places. I think MVC is confusing because the "business logic" goes in the model but most models (like what laravel provides) represent one row in the database so it doesn't make sense when you need to do complex calculations. So I use these Services for the business layer and "Models" for interacting with the database. My understanding is that you use the repository system so that you can later switch your database, but I don't think that is really much of a concern 99% of the time so never used one.

0

u/secretvrdev Dec 23 '20

I am on the side that the model should be filled when created and if you tell me that you write queries for one field. RIP. That wont scale at all.

The repository system gives you a full model back if you call $orderRepo->findByID. But the Repo doesnt care about your Database. Even in my legacy software you could switch the database from mariadb to some other. o problem at all. The Repo uses a query builder which does the abstraction to the sql dialect.

This subreddit got worse a lot without me. RIP

4

u/stilloriginal Dec 23 '20

I just dont understand why you need to wrap a query builder with a repo. I dont see what you gain, and you give up a lot. Honestly how many times have you switched databases? Never I bet.

2

u/remenic Dec 23 '20

The biggest advantage I find to using repositories is the fact that I can just mock the repository in my tests. The advantage to that is that I'm not testing eloquent over and over again, I'm not even hitting a database which means a huge speed boost, even using sqlite, and I'm just testing the code that I wrote. In fact, adding layers seem to help in general with writing tests because it just saves so much execution time.

Only the tests for the repositories themselves hit sqlite, but I'm not really a fan of that because of slight differences between mysql and sqlite.

1

u/secretvrdev Dec 23 '20

Exactly. Also its better to code. Not just tests.

1

u/sinnerou Dec 23 '20

I'm preferring query objects these days. My repositories always ended up gigantic over the lifetime of a project. I feel like query objects are not flexible.q

1

u/helpfuldan Dec 24 '20

Yeah it does seem simple. A quote CRUD application. Create new quotes for database, read quotes in DB, edit quotes in DB, deleted quotes from DB. Default page displays all quotes. Edit button changes it to a textbox that you can save changes. Form to add new ones. Delete button. One php file, like 40 lines for the entire thing?

1

u/pze127 Dec 25 '20

Well, one deliver something like this in 2020, one is automatically out. Good job positions require the candidate to show something more interesting.

2

u/bad-donkey Dec 23 '20

Maybe I'm being a bit naive but it sounds like you can write this like an API. You can use AJAX to hit the different CRUD endpoints. You're folder structure could be something like:

Products Read.php Create.php Update.php Delete.php Objects Products.php

In this example the endpoint would be Products/Read.php and that file would be in charge of headers and grabbing any data passed in and validating. Objects/Products.php would be an instance of the object and you can set it up to have a DB conn as the constructor that is passed in whenever it is called by one of the CRUD endpoints. I dont know if that's what they're looking for or if I am just being super naive.

Sorry for the format I'm on mobile.

2

u/dontc9 Dec 23 '20

It's weird that you post the solution. Probably they want you create a framework or extend functionalities of an existing framework.

2

u/detonator13 Dec 24 '20

Has anyone considered all the other things they would be looking for? As a hiring manager, I want to see if you used git, composer, unit tests, covered security, etc. I want you to be able to talk through your choices. For a senior, I want them to ask questions. I want them to challenge me. I want them to tell me that my rules suck and if they can work outside the box a bit, they can do it in half the time and it’ll be more maintainable. Also, lastly, the choice to ask not use a framework is likely in large part due to having to sift through all the boilerplate to review later instead of just having a couple files to look at.

That said, it could just be a shit company and/or bad interviewer. Never know.

2

u/Envrin Dec 24 '20

Hell, if you don't feel like the job, feel free to send it my way. That type of test sounds right up my alley.

2

u/styphon Dec 24 '20

I'd go back to them and ask what they are looking for and why they want you to write everything from scratch instead of using commonly available open source tools. This test doesn't make sense to me, if you have to write everything you're thinking of then it's crazy.

Now bear in mind I've only got the quote you gave above to go on but it sounds like you're overcomplicating things. In my opinion (and experience as a lead developer) they only want something simple. Yes, they want something modern and utilising OOP, but it doesn't have to be massively complicated. They just want to see you can do what you claim.

Forget the ORM, forget any MVC model, it doesn't need that. No, you can't use procedural code with lots of includes but adding in an autoloader with composer should be trivial for any senior dev (if it's not for you, google it, it's not hard and won't take you long) and so using OOP with that isn't out of the question for an interview test.

Show them exactly what they asked for, a simple CRUD application that connects to a PostgreSQL database using PDO. The PostgreSQL website has some good tutorials and will give you an idea of what your code should look like (but don't be an idiot and just copy/paste it).

2

u/DaveInDigital Dec 24 '20

as a senior who regularly interviews developers, i often ask interviewees to figure out small problems through vanilla PHP not to see how much they know but how they look to solve them. do they ask questions? clarify instructions? pull up documentation? see how others have solved similar problems? i don't need a human encyclopedia, just someone that can efficiently work through problems and who knows how to ask questions when they're stuck or unclear. code is just a vehicle to that. it's assumed from the get-go that your vanilla PHP is going to be rusty, or your PHP altogether when you're away from it for any period of time as you work in other languages. i love when developers immediately pull up PHP docs; everyone should use them at work in real life projects anyway.

also a lot of code out there is still super legacy. it's often not feasible to just rebuild everything with Laravel overnight; more often than not business needs have to be considered (that's how you get paid) and sometimes old projects just need to be maintained or lightly refactored because there's little to gain in a rewrite. a senior developer should have the experience to weigh all these things. often we have experience in our early years going full bore on a refactor and end up causing more bugs and confusion 🤪

in your task, i would write a very simple PDO-based app and include comments along the way explaining my reasoning, what i would do different in a production application, etc. it may or may not be what they're looking for here (this is where asking questions is good, something a senior needs to do often when putting together a project in the planning phase) but if you're true to yourself as a developer, you'll find the right employee-employer match eventually which is a lot more rewarding anyways.

i often thought i was the imposter in the room until i realized almost every developer i respected felt that way too. if anything it just means we realize we don't know what we don't know and that's healthy, keeps you curious and always working to get better.

2

u/[deleted] Dec 24 '20

The biggest issue with frameworks is that there is too much magic, and their tutorials/examples teach you to write code that is tightly integrated and mixed with the framework (symfony and laravel both do that a lot).

On the other hand, Php from scratch is a terrible idea too.

All you need is to understand what a modern framework does for you. There is a very nice Symfony series of articles showing you how to build your own framework using libraries.

https://symfony.com/doc/current/create_framework/index.html

TBH, this should be standard reading for everyone starting on php today.

The second thing that you need, is to learn how to write code that is framework independent. This means that you should be able to move your code from framework to framework to no-framework with just minimal framework-specific glue code.

All big frameworks are guilty of pushing you to let the framework do much of the work that should be done in your business domain code. Or pushing you to mix repository actions with controller or template or business domain actions.

All that on a theoretical level though. In everyday life, you have to do things fast, so you do what you have to and move on.

Now for your exercise, if you can use composer and pull libraries, then half of your problem is solved. You only have to demonstrate that you understand how modern php frameworks work.

7

u/helloworder Dec 23 '20

I would just drop the task and never reply to them. Why waste so much time for this? There are plenty of other jobs to apply.

→ More replies (2)

3

u/JaggerPaw Dec 23 '20

Is this a Web CRUD application or just an application? The web introduces the routing, front-controller stuff, views. Not sure why you need an ORM or "data layer". You are writing CRUD for what? one table?

Autoloading, unit tests, and helpers (which is where validation functions usually live) are all going to be needed. I implement helpers as needed, so as not to over-engineer. If you have a functional function (or series of statements that can be converted), used in some object - make something like a <namespace>/lib/helpers/<object>Helper.php class and stick it in there. Makes it a lot easier to test code now.

3

u/pragmageek Dec 23 '20

They didn't say anything about not using composer.... pick some packages and away you go.

3

u/Xpertbot Dec 23 '20

Includes? Procedural? PHP has come a long way man.... the only include you should have is inside index.Php in your public folder for the bootstrap.Php file that has the auto loading then everything else can go in classes. Architecture wise, MVC is battle tested and it will work. You can create a connection using PDO. PHP IS a view templating system just make sure you include the templates inside a function in a Renderer class so you don’t pollute the global scope with your variables

4

u/sergb39 Dec 23 '20

I may see a point in this task like "see if you can manage without framework and know how to build it by yourself" but why? This is not something you can do in couple of hours and it is huge waste of time.
I really against those kind of interviews where they ask you to do something stupid that you will never do in real life.

3

u/andrewfenn Dec 24 '20

You can easily do this in an hour or less. Unless I am misunderstanding the task they're not saying you can't any libraries, just not full stack frameworks so you could easily composer install illuminate database, a router library, a bit of glue code and you're practically done with the task. They're not asking you to make your own framework from scratch.

2

u/secretvrdev Dec 23 '20

It would show how you can code without support. It should be no problem at all. I would do that in some hours.

3

u/[deleted] Dec 23 '20

The kind of test says a lot about the company. If they would ask me to do this I would politely wish them a nice day and walk away, you don't want to work at a company that don't let you use a framework.

2

u/jstnryan Dec 23 '20

I would have used that as an excuse to build the most incredible single-file, single procedure, IF statement infested, mysql_query awesomeness to ever awesome.

2

u/Chesterakos Dec 23 '20

The only reasoning behind their interview exercise is that they have something on-premises that resembles that monstrosity they asked you about.

I'd really ask myself if I really wanted to work there with that in mind.

15

u/devmor Dec 23 '20

I've asked for demonstrations of similar knowledge hiring for a pure Laravel position because I want to hire programmers that understand how to develop solutions - not Laravel developers that will falter if they encounter something that wasn't covered on Laracasts and can't be found in 15 minutes on StackOverflow.

5

u/oojacoboo Dec 23 '20

Wrong again. Understanding the core of the tech you’re working with isn’t a red flag.

1

u/[deleted] Dec 24 '20

How deep does that go? Processor architecture? Network layers? Browser rendering engines?

We use abstractions like higher level languages and frameworks so we can focus our mental energy on the specific problems at hand, rather than spend 90% of the budget on scaffolding.

1

u/hagenbuch Dec 23 '20

If you can bring value to a place where there is no value: What better place to be?

The only question is then: Will they trust your decisions? Try it right in the interview by being bold. And add value. If they don’t see it, Next.

1

u/umlcat Dec 23 '20

You're used to use a lot of stuff !!!

Keep it simple.

1

u/crackanape Dec 23 '20

Sounds like you've decided you don't want to reply to their coding test as posed. That's up to you.

1

u/32gbsd Dec 23 '20

No hard feelings there are lots of php cargo cult shops who need people like you to help finish their modern php projects. Dont worry about it.

1

u/[deleted] Dec 23 '20

This seems a bit much for a job interview, especially if they're not going to pay for your time spent. I had to do something similar for a different job and the company turned out to be a complete shit show. Writing great code like you mentioned would probably take multiple days, since you're basically writing an entire framework from scratch. I get having programming questions as part of an interview test, but it needs to be scoped down to 1.5 hours at most.

1

u/Kaishiyoku Dec 23 '20

You don't really need anything of that. An autoloader, yes. But everything else? Debatable.

1

u/MorphineAdministered Dec 23 '20

I guess they're looking for specific kind of senior. With such a discrepancy in problem awareness I can foresee your end there with death by a thousand cuts. Wouldn't apply.

1

u/jackistheonebox Dec 23 '20

Don't worry this is how interviews sometimes feel. Don't overthink this as you will get stuck on details.

1

u/[deleted] Dec 23 '20

Once in a while, it's good to revisit/maintain you old 'custom' code that you wrote for a personal project.

1

u/pikknz Dec 23 '20

They only expect 2-3 hours work so just make it work minimally. They mostly want you to do the code securely in queries, i.e. prepared statements.

1

u/illathon Dec 24 '20

Seems kind of excessive for a test application. Is this normal?

1

u/psion1369 Dec 24 '20

The specs don't include much on the way of templating or too much on routing. Just build something that spits out the output after taking in the input on a server param. I wouldn't even consider the routing as it could just be called in the old fashioned way of the direct file. Don't overthink and include what isn't necessary.

1

u/Large-Meat-Feast Dec 24 '20

looking at it from the other end....

Single php class with each method as a static

second php class for DB connection

php page/form that calls the method.

boom!

1

u/[deleted] Dec 24 '20

A very STUPID APPROACH from interviewer.

1

u/[deleted] Dec 24 '20

I don't bother with these tests any more after the last place asked me to build something then ghosted me. Plus I rather do anything other than write code that I know will be thrown away. I have plenty of open source code available for review.

If it's just a short exercise (which this appears to not be) or If I had no job then that would change things of course. Where do these places get off?

1

u/c0ldfusi0n Dec 24 '20

Now you know what is wrong with developers nowadays who depend on frameworks that abstract the knowledge they actually need.

1

u/[deleted] Dec 24 '20

Well

Seems like before attempt to any job interview I'm gonna need to start learning PHP from scratch.

is always a good thing to know.

These types of interviews suck. So the MVP of this isn't that hard tho but, still, you are looking at 1 - 3 hours of work. On top of that: will you be penalized for skimping on testing, error validation, the technique of 'just getting it done'. I can hear feedback like well you used POSTs for updates and didn't use PUTs or DELETES

If you don't need this job push back. If anything you can make them question their interviewing process.

1

u/SavishSalacious Dec 24 '20

That’s not what they’re looking for at all.

They don’t want you to build a framework, they want you to make a CRUD app in RAW php. Why?

I wonder why, what kind of applications are they building? What’s their architecture like? Are they using frameworks? If not this could be scary old school spaghetti code.

If they are using frameworks, they just want to know that you actually know php, and that you don’t just depend on frameworks.

In other words:

Keep It Simple Stupid.

1

u/LordSpaceMammoth Dec 24 '20

Is it a closed book/offline test? There are a lot of results for "postgresql built in php server crud generator" -- you could have one ready to show pretty easily. I mean assuming they are ok with some amount of non-original code; that the exercise is to see if you can get some php written.

1

u/mangelsnc Dec 24 '20

Just chill and analyse: you can use Composer for autoloading, and this is one of the hardest parts of your problem. You can use built-in PDO classes for DBAL, build a super-simple dependency container is like implement a big array... the rest is just the same.

Think out if the box, you don’t need a hyper complex framework to just pass the test.

You can do it for sure

1

u/secretvrdev Dec 24 '20

you can use Composer for autoloading, and this is one of the hardest parts of your problem.

ITS NOT. FUCK ME

Please write your own PSR autoloader and then say that again.

1

u/secretvrdev Dec 24 '20

People in this thread: "I dont do that because i need 10 days for a simple crud app in my standards"

Company: "Go away with your standards that cost to much"

People: D: I AM ANGRY

1

u/baohx2000 Dec 24 '20

Just because you can't use a framework doesn't mean you need to reinvent the wheel. All of the actual components to build a framework (DI, Router, Middleware/Dispatcher, DBAL) all exist. Just search packagist. You just need a bit of glue code to build a micro-framework.

1

u/Deji69 Dec 24 '20

It says not to use a full stack framework, but you can surely use smaller frameworks and libraries. Otherwise they're basically asking you to just whip up your own full stack framework.

1

u/smigot Dec 24 '20

This problem can be solved without a full-stack framework.

1

u/Deji69 Dec 24 '20

I'm sure it can, but the point of them and libraries are to prevent wheel reinvention. My comment is pointing out that there's still the opportunity to build upon existing work.

1

u/Beerbelly22 Dec 24 '20

I love this. I have often the opposite. Not much experience with frameworks as i often can write the code myself faster then learning another new framework. I feel they have a new framework every week.

1

u/c_eliacheff Dec 24 '20

Not an expert but here's what I would like to see from any dev:

  • Respect of SOLID, especially dependency injection
  • Testing
  • Use of PSR, especially naming, autoloader ...
  • PDO, no need for ORM
  • Typings with static checker
  • Modern PHP features
  • Good code style (design patterns, editorconfig ...)
  • ...

1

u/awardsurfer Dec 24 '20 edited Dec 24 '20

you would start with composer. They say “don’t use a framework”, but doesn’t mean “no php libraries”.

So you’d new-up a composer file and start requiring basic packages. Then write your code.

Personally I would pass. it means jack weather I remember PDO or not. It’s like the stupid tests with bitwise questions. Who gives a fuck. Nothing you’ll ever use.

Frankly, I think once you reach senior experience, just go get your own clients and/or contract with agencies. Do your own shyt, make the $$$.

1

u/bensor74 Dec 24 '20

They just want to see if you know how to use PHP outside of a framework. Use composer packages and you'll be just fine.

1

u/2020-2050_SHTF Dec 26 '20

I had this one before, except it was for a junior position, I think :D

The thing about not using a web server is just so you don't write anything in a config file like .htaccess, that might do some rerouting.

For the db, I used someone's singleton class from GitHub, which I mentioned of course.

Then I used composer for namespacing stuff and just wrote some classes that were then called via scripts referencing the crud calls.

At least that's what I remember doing. I got an interview, but not a job from it. They did say it was the reason I got the interview though.

1

u/welterwerk Dec 26 '20

but please don't use full-stack frameworks like Laravel, Symfony or Code Igniter, also don't use Apache or Nginx, just use the built-in PHP server and PostgreSQL

You can still use packages via composer, right? If so, it is not a big deal to accomplish that task. There are a lot of great packages which resolve most common issues – like routing, database connection, templating system. You just need to gather them up and use.

1

u/breich Dec 28 '20

I think if it were me I'd ask for some clarification. It sounds like your head immediately started thinking about "what framework components do I need to build the solution in a flexible, forward-thinking way?" So did they want you to build the framework to solve the problem, or solve the problem in plain PHP? I suspect the latter.

1

u/zvive Dec 28 '20

I was given a similar thing, but was told to use a specific routing package.... so I basically made my own laravel clone(ish), using the router, propel for migrations, etc... it said not to use a framework, but you can still use packages I presume? If so, just use some packages to get you half way there, it's still easier than not using a framework and not using any packages.

1

u/Jurigag Dec 30 '20

some kind of basic template system to display standard HTML views;

In today days you use API in 90% cases

something that at least resembles a ORM or a well organized Data Layer;

Don't need it so much to simple CRUD application, DBAL will be enough

not to mention basic validations

You can do validation on __construct of classes and simply throw exception.

1

u/ltsochev Jan 04 '21

So, using PDO is too hard now and writing a model with built-in SQL is a no-go nowadays? I don't know man. I've been working with PHP for over 10 years. If I have to go to an interview or some certification test and they ask me to do A I'll fucking do A in the shortest amount of time possible. If they want me to create something actually useful, they'll need to pay me.

Bonus points for using PDO ... prepared statements - bye bye sql injections.

Back in the day ... before frameworks, all that we did when we started a new project was to re-invent the god damn wheel and write a new but slightly different database wrapper class :D Should work splendidly at an interview. For more, like I said, they'll have to pay me.

1

u/x_mk6 Dec 24 '20

Bro you're 12 how experienced could you possibly be lol

1

u/[deleted] Dec 23 '20

It might be one of those projects that isn't supposed to be perfect, but allows them to see into how you think

'php -S localhost:80' to start the dev server if you don't know

Throw in a docker postgres instance, easy. Id personally wrap it into a docker-compose so they can easily type 'docker-compose up'

Document well, add good test coverage

For the db layer, id make a repository/dao object per entity and use heredoc to write nice queries. Use pdo with bound params.

For models, id define the private props and make getters and setters. Check out jms serializer to write to json

1

u/geggleto Dec 23 '20

my advise would be to run away, far away

0

u/BONF1RE Dec 24 '20

Y’all realize this is satire, right?

1

u/pze127 Dec 25 '20

I wouldn't do that. I'm currently unemployed and the interview request was a true fact.

0

u/SmotherMeWithArmpits Dec 23 '20

Sounds pretty fair besides the not using apache/nginx part, tell that guy to go smoke some more crack

13

u/Fit4BJJ_Pat Dec 23 '20

it's for an interview, the built in server is more than capable enough for that...

3

u/KFCConspiracy Dec 23 '20 edited Dec 23 '20

I think that part's probably actually a good idea. I don't want to deal with any kind of configuration idiosyncracies to test your project. The one thing about PHP -s is it just works... Check the project out run the command it starts serving no config needed, doesn't really matter what OS either is using. That's actually kind of doing OP a favor.

I don't really like the project overall though because I value my time too much to spend a few hours on a take-home.

-4

u/[deleted] Dec 23 '20

LOL that is ridiculous. I would definitely use some libs & composer, not gonna write all that if they want to see good code quickly

1

u/secretvrdev Dec 24 '20

You dont know what a fullstack framework is. Youre out.

0

u/guice666 Dec 23 '20

I used to give tests regarding the language itself, little "gotchas" you'd only hit when using PHP directly. For example, using an if (strpos()) - asking them what will happen and why.

0

u/wavewakerz Dec 24 '20

Me for my part hate working with frameworks. To much overhead and performance drop. Better write everything yourself in a way you need it. Whenever I was in companies using big frameworks like laravel or symfony we always ended up migrating to a selfmade system.