r/PHPhelp • • Oct 30 '13

Going to apply for Jr PHP dev jobs, what should I absolutely know?

11 Upvotes

I minored in comp sci at college and have been programming on the side on my LAMP stack for the last 3 years. I'm bored at my day job (insurance sales) and want to start looking at programming jobs. My main project in my portfolio is an insurance agency database management system that has taken a lot of work and I am fairly proud of. I had to design the SQL schema, write all the PHP code to retrieve data and display the pages/forms, and learn CSS and javascript so the user could modify things on his/her end.

As far as my weaknessess, I haven't used any OOP PHP besides PDO for my projects, but I do understand how OOP works from C++ in college. Also, I haven't yet started using a framework like Cake. Aside from these things, what else would you recommend I make sure I know for a Jr dev role? Any advice would be greatly appreciated. Thanks!


r/PHPhelp • • Apr 27 '26

Runtime vs InvalidArgument exceptions - when to use which?

10 Upvotes

When should you throw RuntimeException vs InvalidArgumentException in PHP?

I understand that InvalidArgumentException extends LogicException, which is meant for errors detectable before runtime, and RuntimeException is for conditions only discoverable during execution.

But I keep second-guessing myself on cases like this:

function getFile(string $path): string
{
    if (!file_exists($path)) {
        throw new ???Exception('File not found.');
    }
    return file_get_contents($path);
}

The argument $path is technically valid -- a non-empty string, correct type. But the file it refers to does not exist. Is that a RuntimeException because the absence is only discoverable at runtime? Or is it an InvalidArgumentException because the argument I passed did not correspond to anything real?

Where do you draw the line, and how do you think about this distinction?


r/PHPhelp • • Dec 16 '25

Solved Difference between comments

10 Upvotes

JUst wondering, what is the difference between

/* */

and

/** */


r/PHPhelp • • Oct 15 '25

Token-based vs Cookie-based Auth for Laravel Apps in 2025?

10 Upvotes

Hey everyone! 👋

I’ve been working on a Laravel + React SPA setup, and I’m torn between Sanctum’s cookie-based session authentication and the more traditional token-based approach (using bearer tokens in headers).

From what I understand:

  • Cookie-based is great for web apps — CSRF protection, automatic session handling, etc.

  • Token-based is simpler for APIs and mobile scalability — just attach the token in headers.

Given how modern apps are often both web and mobile (and considering things like scaling, security, and ease of integration with frontends), which one do you think is better suited nowadays for Laravel apps?

Would love to hear what you’re using in production and why 🙏


r/PHPhelp • • Sep 13 '25

How to Smoothly Migrate My ERP from PHP 5.6 to PHP 7 or Higher

10 Upvotes

Hi,We are currently using a very outdated PHP version (5.6) for our ERP system, and we would like to upgrade to a more stable and modern version of PHP. However, our ERP is quite large and consists of many critical modules that are used constantly in production.Due to the significant differences between PHP 5.6 and newer versions (e.g., syntax changes, deprecated functions, etc.), we are considering a gradual migration approach.

Could you please guide us on how to smoothly migrate to a newer PHP version without disrupting our production environment?


r/PHPhelp • • Jul 15 '25

Php db connection

10 Upvotes

Hi, i have been learning php and i am learning pdo class and mysql database. I am using xamp at the moment for local development. I have a question about db connection.

When i connect to a database with 'index.php' for ex and i use pdo class, does that connection end when i close the page? I've read that i have to connect to the db once, otherwise multiple connections can damage the database.

But as i understand, when i close the page, the connection dies. So is it ok to reconnect db everytime by opening index.php if i close it?


r/PHPhelp • • May 19 '25

Looking for feedback on a PHP WebRTC library I’m building

10 Upvotes

Hi everyone,

I’ve been working on a native WebRTC implementation in PHP, and I’d really appreciate any feedback or thoughts from the community here.

The project is open source and aimed at use cases where developers want more control over WebRTC from a PHP environment.

Here’s the repo: https://github.com/PHP-WebRTC

I’m still iterating on it, so if you have suggestions, questions, or want to test or contribute, I’d love to hear from you!


r/PHPhelp • • Nov 29 '24

Why use PHPStan/Psalm if PHPStorm is doing the same thing?

10 Upvotes

Recently got back into coding after a hiatus of about 15 years and have been delighted at the changes with PHP. Also switched to PHPStorm and I am astounded how much better the coding experience is as compared to SublimeText.

PHPStan/Psalm are two of the tools most frequently suggested as essential - however I am wondering if these are only useful to people not using PHPStorm?

PHPStorm is already alerting me to code issues - such as undefined variables.

Would PHPStan/Psalm offer me any major benefit?


r/PHPhelp • • Nov 01 '24

Is adding an ORM to a legacy PHP project a bad idea?

10 Upvotes

So basically what the title says. There’s this project that is a pain to work at my job. Queries are just plain SQL and not everything is escaped properly so it causes issues between MySQL versions. Idc one way or another but this just seems like bad design. What are your thoughts?


r/PHPhelp • • Oct 09 '24

Is Laravel Used by Big Tech Giants? Future Scope in 2024 and Beyond – Should I Learn Django Instead

10 Upvotes

I’ve been exploring different web frameworks and am particularly interested in Laravel. I’ve heard mixed opinions about its use in the industry, especially regarding whether any big tech companies rely on it.

  1. Industry Usage: Are there any notable tech giants or successful companies using Laravel for their projects? I’d love to hear about real-world applications and how Laravel fits into their tech stack.

  2. Future Scope: Looking ahead to 2024 and beyond, what’s the outlook for Laravel? Is it gaining traction, or are there trends suggesting it might decline in popularity?

  3. Django Comparison: Finally, I’m considering learning Django as well. How does it compare with Laravel in terms of job opportunities, community support, and overall future relevance?

PS: I'm just a newbie curious about laravel and my future as well :-)


r/PHPhelp • • Jul 22 '24

I'm looking for a learning resource that will help me get a more in-depth knowledge of PHP and developing using OOP & Design Patterns. What would you recommend?

10 Upvotes

So far it looks like the best example would be using, Program With Gio - Learn PHP The Right Way

https://www.youtube.com/playlist?list=PLr3d3QYzkw2xabQRUpcZ_IBk9W50M9pe-

Are there any other suggestions?

Thanks!


r/PHPhelp • • Jun 04 '24

Why is "//" more common than "#" in code comments?

10 Upvotes

I've always used # to start a comment on my php apps, but recently I've been seeing "//" is being used a lot more often. For example, Laravel codebase never uses #

Is there a bigger reason for that, or is it just personal preference?


r/PHPhelp • • Dec 23 '23

Solved Do I need to make a while loop just to get one row from the database?

10 Upvotes
$query="SELECT * FROM category where cat_id= 2";
$result=mysqli_query($connection, $query);
 while ($row = mysqli_fetch_assoc($result))
 { $itemId = $row['cat_id'];
 $itemName = $row['cat_name']; }

r/PHPhelp • • Apr 23 '23

Solved What is technically happening in the server when you "prepare an SQL statement"? $mysqli->prepare($sql)

10 Upvotes

mysqli::prepare -- mysqli_prepare — Prepares an SQL statement for execution

I don't really understand when you say "prepare an SQL statement", what actually is happening?

$stmt = $mysqli->prepare("SELECT username FROM users WHERE username = ?");

r/PHPhelp • • Mar 21 '23

Resources on coding WELL in a PHP?

10 Upvotes

About a year ago I started a new job that uses a lot of PHP. I've been able to pick it up as necessary along the way well enough to meet the demands of the job. However, I'd like to start improving things about our codebase. Part of that is introducing better patterns to our codebase.

I'm looking for resources on good programming patterns in PHP. I find PHP's lack of strong typing to be very frustrating to deal with in our codebase. Type hinting but no generics. Arrays that represent both sequential data and key-value pairs. No enums.

The underlying data is messy and they're not using an ORM. Introducing an ORM at this point is not feasible so we work directly with SQL strings. So one common thing are methods with lots of branching to generate a SQL string.

They updated from PHP 5 to PHP 7.4 some time ago. But our dependencies are out of date. We are stuck with PHPUnit 5-something and we have no mocking library. Their testing is terrible. I'd love to find a way to update PHPUnit but it will probably break a lot of people's code.

It seems to me that being productive on a large codebase in PHP requires having strong conventions in place. Unfortunately, that ship sailed long before my time at this company.

Are their good PHP-specific resources on useful, reusable patterns? Or do I just need to adapt patterns from other languages to PHP?


r/PHPhelp • • Feb 08 '23

Solved pdf generation

10 Upvotes

I have requirements to generate pdf with more than 30 pages dynamically based on the user query. The pdf not contains much images only text in the form table. Planning to wkhtmltopdf library for this. Just wanted to know it's affect the execution time Or memory. Anyone help me to understand this.


r/PHPhelp • • Nov 12 '22

CSV to HTML Table via Array not working

10 Upvotes

I am trying to turn my CSV file into a HTML Table

        echo "<pre>";

        $handle = fopen("quotes.csv", "r");
        while (($data = fgetcsv($handle)) !== FALSE) 
        {
        foreach (explode("\n", $data[0]) as $line) 
        {
            print_r(str_getcsv($line, "|"));
        }   
        }
        echo "</pre>";

This code creates an array as I was checking the format of the CSV

Array
(
    [0] => The old world is dying, and a new world struggles to be born; now is the time of monsters.
    [1] => Antonio Gramsci
    [2] => 1891-1937
    [3] => https://en.wikipedia.org/wiki/Antonio_Gramsci
    [4] => https://upload.wikimedia.org/wikipedia/commons/e/e6/Gramsci.png
    [5] => politics
)
Array
(
    [0] => They'll say we're disturbing the peace, but there is no peace. What really bothers them is that we are disturbing the war.
    [1] => Howard Zinn
    [2] => 1922-2010
    [3] => https://en.wikipedia.org/wiki/Howard_Zinn
    [4] => https://upload.wikimedia.org/wikipedia/commons/e/ef/Howard_Zinn%2C_2009_%28cropped%29.jpg
    [5] => politics
)

The table below tells me $data is not an array

<table>
    <tbody>
    <?php foreach($data as $row)
    {
        ?>
        <tr>
        <td><?=$row[0]?></td>
        <td><?=$row[1]?></td>
        <td><?=$row[2]?></td>
        <td><?=$row[3]?></td>
        <td><?=$row[4]?></td>
        <td><?=$row[5]?></td>
    </tr>
    <?php  } ?>
    
    </tbody>
</table>

So how will I put this array into the HTML table?


r/PHPhelp • • Sep 19 '22

How to move up to PHP 8 and Object Orientation?

10 Upvotes

I first learned PHP about 15 years ago, self taught, from a book.

Every few years I use it for a project & it's time for another now. I just upgraded my PHP to PHP 8 and think that's it time to start using modern language features and Object Orientation, as I do in other languages.

Without being mind-numbed by the basics, what's a good training course on Udemy, etc, or series of Youtub videos?

BTW, my PHP never (ever, ever) serves HTML. I use it solely as a RESTful HTTP(S) API. Also, I think that I will be replacing my own homebrew utility code by Laravel.


r/PHPhelp • • Sep 19 '22

PHP and VS Code

10 Upvotes

I decided to start using VS Code instead of Notepad++ and am trying to get the environment set up.

I know of Intellisense and Xdebug.

What other extensions do you recommend?

Any other tips?


r/PHPhelp • • Aug 08 '22

I mostly do React and React Native but I want to learn PHP but I don't have any PHP dev environment. What's the PHP equivalent to something like NPM? Is it Composer? Is it normal to have NPM and Composer installed for one project to handle the backend and front end separately? Thanks

10 Upvotes

I'm working on basic project for now (just HTML and vanilla JS for now but I also use React on other projects) and I want to learn more about the PHP dev environment. Is the Node/NPM equivalent of PHP Composer?

What would be the best and most reliable source for learning a PHP dev environment?

For example, I want to use a QR code library to generate QR codes for the user's accounts. At the moment, I can use PHP or JS to make an API call to generate the QR and display it on the page but what would be the best way of having a PHP library/package?

I know I can Google all that but I was wondering if you know any trusted reliable source.

Thanks


r/PHPhelp • • Feb 09 '22

ELI5: how to add a Remember Me (aka Keep me signed in) option to a log in screen? I have checked a few videos and tutorials and they all seem to have security flaws like suggesting storing the username and password in a cookie! Any reliable sources (I usually prefer videos). Thank you

10 Upvotes

Hi

Well, the title. But yeah I need to add a Remember Me option to a sign in and I don't know what approach would be the best one because it seems like every tutorial I see, lots of reviews/comments say that there is a major security flaw there.

Where do I begin? Do I need to make any changes to my database for this (like a new table to store anything)?

Generally, I have understood that I need to store a completely random string in the cookie and the same string in the database. When the user comes to the log in page, I first see if that string exists in the cookie, if yes then I check if that string exists on the database. If it does, the code automatically fetches the user's data, starts a new session and logs the user in. Is that more or less how it should be? If yes, do I need to create a new table that stores these strings only and the user's id?

Thank you


r/PHPhelp • • Feb 08 '22

Code injection freaking me out. Is it safe to run a strlen($_POST["password"])

10 Upvotes

Probably just my paranoia getting the better of me but I'm doing my first real website (outside of assignments and stuff at school which have zero consequences) and I want to be thorough.

So I'm doing everything I can to prevent code injection but right now that just boils down to trim(), htmlspecialchars () and stripslashes() to all user input. (And doing the whole PDO thing for sql.)

The thing is i don't want to be trimming people's passwords without letting them know. (Should I even let them know? It's not like they'd notice) so right now I'm thinking of doing

if(strlen(trim($_POST["password"])) != strlen($_POST["password"])){
// Tell them not to start/end with spaces
}

but everything I've read is freaking me out and it feels like running any sort of operation on raw input is going to leave me open to something.

Thoughts?


r/PHPhelp • • Nov 20 '21

Should I use Docker?

10 Upvotes

I'm a PHP (mostly laravel) developer. I currently use laragon as my dev env. I love to move to docker, because to try and learn it. But building dockerfile and for each project is a pain in the ass. Is there any other dev friendly way to create dockerfile? Or should I continue using laragon? (I heard about Laravel Sail, But some of my projects are not fully laravel)


r/PHPhelp • • Nov 18 '21

Best Excel lib for PHP

10 Upvotes

So I'm going to create a excel extract option with the data retrieved from my database, but which excel lib is the best to use in 2021?

The Excel lib should be able to create sheets, and columns with colors, and merging cells together etc.

I see that there is a lot like PHPEXCEL, PHP EXPORT DATA & PEAR EXCEL WRITER, but what are your experience with this and what should I choose?