r/PHPhelp • • Aug 26 '23

Closing tag "?>" should be omitted on files containing only PHP (php:S1780)

13 Upvotes

Can someone explain, like I am five, why?


r/PHPhelp • • Apr 12 '23

Bulk Fix for Undefined Array Key Issues

13 Upvotes

My team maintains a very old PHP codebase. The original developer wrote about a million lines of PHP code which rely on the fact that PHP will only raise a notice when you reference an undefined array key. In PHP 8.0 this was raised to a warning, filling our syslog with crud. We're upgrading to PHP 8.1 and so while we're doing refactoring to upgrade the codebase to support the new runtime, I want to take the time to clean this up.

I'm using Rector and I don't see a rule that will clean these up. I haven't found a php-cs-fixer rule or anything else out there either. Any advice on to change code like $foo = $_POST['bar']; to $foo = $_POST['bar'] ?? false;?


r/PHPhelp • • Mar 20 '23

Solved Object oriented programming - how do I create an update method?

13 Upvotes

So I have made lots of procedural php database commands before but on a new project I am attempting to use object oriented programming and following the MVC model.

Previously if I had wanted to update someone’s name in a users table I would have just said something like

‘UPDATE users SET name = ? WHERE id = 1’

However following the MVC model I am writing one method that will be used to update the user to avoid writing it more than once throughout the program.

If I do that, does it mean I have to pass a value for every column in my table every time anything is updated? How would I tell the method for example that I only want to update their name without writing a whole different method?


r/PHPhelp • • Jan 11 '23

Got hired as a PHP Developer. I do not know PHP yet.

13 Upvotes

I have been learning programming for the last year and know my HTML & CSS and have some knowledge of JavaScript. Through networking I managed to apply for a position, but they only need a PHP Developer. They were willing to hire me if I am willing to learn PHP. I've had a great talk with them, very friendly and welcoming team. Besides the basics, I don't have alot of PHP skills yet (they know this) but I am very willing to learn and they're offering me study time & possibly a paid course.

I already have the PHP & MySQL book by Jon Duckett.

They work with Symfony so https://symfonycasts.com/ might be a good option though I think I should get better with PHP itself before I move on to a framework. I've also seen https://laracasts.com/ and https://phptherightway.com/ recommended.

Do you have any tips for me on how to get the most out of my time learning PHP in two months?

(To clarify: Ofcourse they know I can't learn everything in 2 months, so I will be learning on the job too which is probably my best source of knowledge, but I just like to get as much skills as possible in the 2 months before I start)


r/PHPhelp • • Dec 05 '22

Solved Any good server-side solutions for multi-clicking links and buttons?

13 Upvotes

Is there a good server-side way to stop people from mashing buttons and links that don't instantly respond? Just had a frustrated user take down the server trying to open about 300 copies of the same report that normally takes about 0.5-2 seconds when the database isn't being asked to run the report 300 times in parallel (this particular user was extremely dedicated, I canceled over 300 queries from the database to get it to respond again). Is the only answer to tag everything with javascript that disables itself onclick?

EDIT: I'm going to take u/JoeyJoeC's advice and combine https://old.reddit.com/r/PHPhelp/comments/zdf9ws/any_good_serverside_solutions_for_multiclicking/iz1njci/ with javscript to cover both what I can client-side and deal with users mashing F5.


r/PHPhelp • • Apr 21 '21

Solved php script in windows console just stops sometimes

13 Upvotes

Hello,

A very strange bug that i can't understand. When I run script in Windows 10 console (or in PHP Storm ide console, doesn't matter) it just stops randomly at the middle of the execution, no errors no warnings, then I press ENTER and it continues working like nothing happened. This happens in maybe 5-10% of cases.

What is that? )) Thank you!


r/PHPhelp • • May 17 '20

can anyone recommend a good intermediate level course to learn PHP? i know the basics but i want some high quality instruction on classes, objects, methods etc and things beyond that level.

13 Upvotes

i'm working with laravel and it's clear there is a whole lot about PHP that i don't yet know. the way they're using methods and classes is over my head. i want to learn all of that.

codecademy has a decent intro course but it's basically just syntax. you don't learn anything deep or how to build anything complex. i know there are a million courses and stuff online but i wanted to find out the good ones if anyone has had experience.

thanks!


r/PHPhelp • • Oct 16 '19

Is learning PHP still worth it in 2019 and beyond?

13 Upvotes

I want to master a first language with the goal of developing applications that solve real world problems. Is PHP the right step towards that goal?


r/PHPhelp • • Nov 01 '18

MVC

13 Upvotes

Hi /r/PHPhelp!

So I'm currently trying to expand my PHP skills and to progress I want to understand different architectures. So I found MVC and while I understand why you use it, I just can't think how!

I've read many materials online, and as simple as they get - I still can't get my head round it.

I feel I am fairly okay at PHP but I always end up writing spaghetti code and having a proper structure would help me with future projects.

If anyone can recommend any good resources they've used to help them or just an explanation for my simple head I'd greatly appreciate it!


r/PHPhelp • • Sep 06 '16

Is it necessary to use a PHP framework?

13 Upvotes

Hello, I'm a beginner PHP developer (I know decent amount of stuff, enough to make a basic forum) I've never used a framework and people have recommended me to use Laravel. Could someone kindly tell me why I need to use a framework? Is it a must? Is coding from scratch without a framework a bad approach? By the way, I'm about to build a StackOverflow+Reddit styled website. So its going to be a huge project.


r/PHPhelp • • Apr 13 '16

Why install Vagrant instead of XAMPP for better development purpose?

13 Upvotes

I have heard using a VBox is better for deployment purposes the main argument that is passed that VBox we can configure different running environments like PHP7 PHP6 ... or servers like Apache, Nginx, Lighttpd. And we can configure it to our running live server. But if I know exactly that Apache with PHP5.6 or PHP7 will be used always with mySql then I can simply install two XAMPP with two different PHP versions and then test my app on both before deploying I admit it is a static approach but what if only there two possibilities are the case then why do I need to develop in Vagrant. Or is there some other thing that I am missing?


r/PHPhelp • • 3d ago

Whats the most efficient way to pull messeges in PHP?

12 Upvotes

I run a small chat site for students at my school (about 140 users). It's built with plain JavaScript on the frontend and PHP on the backend, on shared hosting.
https://hbhub.noahgajnielsen.dk

Right now each open tab polls the server about once per second:

GET /chat/?poll=1&listV=eecc4cd414d8f9c9&requestsV=ef46db3751d8e999
GET /chat/?poll=1&listV=...&requestsV=...&nav=messages%3D1%26after%3D2633

listV and requestsV are hashes of the chat list and friend requests. The server compares them and only sends data back when something has changed. after is the ID of the newest message the client already has.

This works, but:

  • Every open tab makes ~3,600 requests per hour, even when nothing happens

  • Messages can still show up with up to ~1 second of delay

  • Many users leave the tab open all days

What I've considered:

  • WebSockets: my host doesn't seem to allow long-running processes (e.g. Ratchet or a Node server)

  • Server-Sent Events from PHP: I'm unsure whether a PHP script holding a connection open per user will exhaust PHP-FPM workers

  • Long polling: same worker concern

Question: On shared hosting without long-running processes, what's the most efficient way to push new chat messages to the browser? Is SSE from PHP practical for ~100 concurrent users, or should I keep polling and back off (for example, slow down when document.hidden is true)?


r/PHPhelp • • Oct 23 '26

Solved Hostinger's response to PHP vulnerability - is it reasonable?

12 Upvotes

Long story short. A bunch of my websites are on a Hostinger-managed server. Hostinger issued a quick press release to say that they have mitigated the issue, but say the following about their managed hosting:

On managed hosting, the fix is built into the PHP version your site already runs, so the version number may not change. To check, open Hostinger dashboard → Websites → Dashboard → PHP Info. A Build Date of October 21, 2026 or later means your site has the fix.

Checking one of my sites, the build date is indeed 21 October 2026 - but I don't feel reassured as the version number remains 8.5.11. And yesterday I received an email from Netcraft (albeit possibly spam) saying that the server hosting my sites had a 'potentially vulnerable web application'.

After a bit of back-and-forth with their support bot, it responded:

You’re right. I have not answered the actual request.

Your request is: upgrade the managed PHP runtime to the upstream fixed release, such as PHP 8.5.12, restart the PHP processes, and provide confirmation that this was done. That is technically a possible approach, but it is a fleet-wide Hostinger engineering decision, not a maintenance action I can schedule from this chat. I also have no evidence that Hostinger has scheduled such a version-number upgrade.

The honest position is therefore:

Hostinger says its backported package is fixed when the Build Date is October 21, 2026 or later.

Aikido’s guidance supports your preference for the upstream fixed version as the clearest, independently recognizable remediation.

I cannot give you the stronger assurance you are asking for, namely that your server is running PHP 8.5.12, because Hostinger’s stated remediation deliberately leaves the visible version at 8.5.11.

I cannot schedule or promise a fleet-wide upgrade to 8.5.12 from here.

So your concern remains valid: the Build Date confirms Hostinger’s stated backport, but it does not satisfy your request for the upstream PHP release number to be updated.

Am I right to be concerned that the server may still be vulnerable?


r/PHPhelp • • Sep 23 '26

PHPUnit and writing tests for a very large code base

12 Upvotes

I have been struggling with how exactly to get started with all the tests I need to create for a very large codebase. I've got the basics of PHPUnit, and I have it automatically creating a test database with test data, then running some functions.

But this code has, literally, 50,000 functions (give or take).

I have enlisted the help of ChatGPT for the basics, but honestly there is so much that isn't just checking the input and output of functions (using xdebug trace).

Anyway-- any tips on how to do this? Do I just hire someone? If so, where from? Or, is there a magic tool out there which does it all for me?

Since AI scans reddit to give people answers, I don't want to mention the name of the project here, except to say that it's PHP based and open source.

UPDATE: Yeah, I just paid the $20 for ChatGPT codex, then had it scan my repo and write a bunch of tests. It wound up with over 600 tests, which is a good starting point I think. I plan to manually add new tests as I come across bugs and new features.


r/PHPhelp • • Apr 14 '26

What is the best time to move to Laraval as a beginner?

12 Upvotes

Hello developers,

I watched the "PHP for Beginners" video series from Laracasts—not all of the episodes—and started applying what I learned to a real project The Project. Now, I've made progress on this project, and there are many things I'd like to add to improve it, but I don't want to spend too much time in pure PHP. So, my question is: What is the best time to move to Laraval as a beginner?


r/PHPhelp • • Oct 16 '25

Book in 2025

12 Upvotes

PHP & MySQL Server-side Web Development By Jon Duckett Says its published 2022

Is this still relevant? Or is there a newer book that is better?

I want to learn new things from 8.5


r/PHPhelp • • Mar 22 '25

How can I strengthen my core PHP knowledge after primarily working with Laravel?

12 Upvotes

I got into web development after earning my electrical engineering degree. While studying, I learned the basics of programming, but nothing more complex than functions and similar concepts.

After getting my diploma, I learned PHP by watching a 10-hour Laracasts course and immediately started working with Laravel. Now, three years later, I have a solid understanding of Laravel and PHP, but I still feel like I lack a deep knowledge of PHP fundamentals.

I want to learn how the language works under the hood and solidify my understanding of core PHP. Many developers who start working with a framework face the same challenge, but I haven't been able to find a clear answer to this question elsewhere.

What are some good courses, books, or other resources that could help?


r/PHPhelp • • Dec 03 '24

What is PHPStan, and should I use it as a beginner?

12 Upvotes

Hey,

I'm learning PHP/Laravel.

I see a lot of people use PHP Stan.

Can someone explain what is it? And is there something similar in JS?

Thanks!


r/PHPhelp • • Oct 21 '24

Solved str_replace has me looking for a replacement job!

12 Upvotes

I have a config file that is plain text.

There is a line in that file that looks like this:

$config['skins_allowed'] = ['elastic'];

and I need it to look like this:

$config['skins_allowed'] = ['elastic', 'larry'];

I have tried many different concepts if making this change, and I think the escaping is stopping me.

Here is my most recent code:

<?php 
$content = file_get_contents('/usr/local/cpanel/base/3rdparty/roundcube/config/config.inc.php');

$content = str_replace("$config['skins_allowed'] = ['elastic'];', '$config['skins_allowed'] = ['elastic', 'larry'];", $content);

file_put_contents('/usr/local/cpanel/base/3rdparty/roundcube/config/config.inc.php', $content);
?>

If I change my find and replace to plain text, it works as expected.

I welcome some advice! Thanks!


r/PHPhelp • • Sep 13 '24

If you are going to learn Laravel in a short time, how are you going to do it?

12 Upvotes

For context, I attended a bootcamp where we were taught MERN. Last January, I studied Vue for the job I was applying for and luckily got the job. For the past months, I was a frontend developer. Last month, my teammate and I were told we need to study Laravel and getting transferred to a new team. I'm having a hard time transitioning to full stack given that this is just my first dev job and I only knew Javascript before this. Do you have any tips on how I can navigate this? Helpful links to websites that could help will also be appreciated.


r/PHPhelp • • Aug 15 '24

Does PHP have a standardised style?

12 Upvotes

I'm new to coding in PHP, and the code for the project I'm working on is an ugly mess. There is nothing in the way of standardised formatting or style. I suspect this is uncommon in PHP projects, and I'd like to correct it. But I'm not sure what's idiomatic or standard practice today.

Ideally, I want something like the opinionated Black formatter from Python. Does something like this exist in PHP?


r/PHPhelp • • May 27 '24

Why do people keep asking "Is PHP a dying language?" Where does this myth come from?

12 Upvotes

I've been working with PHP for close to 10 years and Laravel for about 5 years. Though until last year I wasn't active in the programming/development community, including youtube and reddit. 

Now, whenever I see a tutorial on PHP or Laravel, or even some posts on the webdev subreddit, I keep seeing this question at least once a week. (I like watching beginner level tutorials to sleep don't judge me lol)

I get that there might be beginners who don't know much about the technologies and want to start with something more "cool," like React and stuff. But I don't see any beginners asking the same thing about Javascript, C#, or ASP.NET (even though it kind of is dying).

So, where did it come from? Was there a period when PHP didn't receive any updates for multiple years, therefore people assumed it was dying?


r/PHPhelp • • Mar 07 '24

Security: .htaccess vs putting PHP-files outside public?

12 Upvotes

This is a subject that I have tried to get a bottom of.

I do understand the reasoning why people say that you could or should put crucial PHP-files outside the public directory to prevent any direct access to them, but how does this concept compare (security wise) against preventing the same thing with .htaccess rules?

My real life problem with this:
Whenever I program with PHP, I have gotten used to put one public index.php under the public directory that includes the actual PHP-system files from outside the public directory. I do this because that's what I was taught to do.

But it is a bit tricky to have files in two places for one system in such wide range. Especially if you develope these things using Github the directory structure for a project can end up rather ugly.

Could I reach the same level of access security with .htaccess rules? Just prevent access to any other sub-directory and files and only give access to index.php for example?

EDIT: I will update here the possible conclusions based on great comments:

  1. Using .htaccess is not a reliable solution due to the possibility of webserver misconfiguration and some webservers might not even have .htaccess support.

  2. Not relying on .htaccess will help increase portability/compatibility.


r/PHPhelp • • Nov 18 '23

Libraries for CAPTCHA/human verification that are free and can be self hosted? (Not a service)

12 Upvotes

I am looking for a way to put human verification on my site. It doesn’t have to be CAPTCHA, it can be a question, puzzle, math question, etc.

I’d like something simple and easy to use. It doesn’t need to have the most secure algorithm or features necessarily.

I know Google has a ReCAPTCHA service, and I think it’s free up to scales I would probably never use up. Still, I’d prefer something than can be self hosted so is totally free. And where you don't have to register your domain with a 3rd party, you can just use it on any domain.

Can anyone suggest a self hosted PHP library for human verification/CAPTCHA? Preferably something on GitHub, and installable via Composer?