Skip to main content
Share Your Experience: Take the 2024 Developer Survey

Questions tagged [php]

Questions about PHP, a widely-used general-purpose scripting language that is especially suited for Web development.

Filter by
Sorted by
Tagged with
0 votes
1 answer
160 views

Our php codes base has 6 different ways to do INSERT … ON DUPLICATE KEY UPDATE, how do I fix it?

Our php codes base has 6 different ways to do INSERT … ON DUPLICATE KEY UPDATE. It happened over years because the php framework is evolving and my team members come and go, although I won't say we ...
Qiulang 邱朗's user avatar
2 votes
1 answer
158 views

How is $this provided in PHP?

I got a fundamental question about the $this keyword in PHP and how it is defined. Pracitcally, I know what it is and what it does. But I am interested in how it is provided / implemented? For example,...
tweekz's user avatar
  • 227
2 votes
2 answers
324 views

Unit testing for non-stateless units - how?

Firstly let me say I have never written a unit test in my life. I am trying to get the hang of PHPUnit, and so far it's working pretty well for me so far as "stateless" functions (that ...
Brian Smooner's user avatar
-1 votes
1 answer
82 views

Best practices for organising PHP files?

I am currently writing a PHP / JavaScript application library, which I intend to use in the future for several other applications. The library includes functionality for handling a database, creating ...
Brian Smooner's user avatar
0 votes
2 answers
256 views

Should I split backend into legacy and modern app to make the rewrite feasible?

My vanilla PHP backend app needs to be rewritten due to very poor design and lot of unstructured code. The legacy app is very large and the team small, so doing full rewrite in limited time is quite ...
user14967413's user avatar
0 votes
0 answers
23 views

An IoT client and MVC-based server. Data model with different fields per type?

The problem Let's assume such scenario: List of IoT devices (one model?) Each list item has (among other fields) a type field Depending on the value in the type field, device may report different ...
trejder's user avatar
  • 2,396
1 vote
3 answers
218 views

frontend server obtain data from backend server, or frontend server return page with javascript that obtain data from backend server?

I'm currently learning how to separate frontend server and backend server. However, i'm not sure which approach should i take between the two Frontend server obtain data from backend server and ...
LLL's user avatar
  • 111
2 votes
1 answer
159 views

What is the proper pattern for a singleton SETTINGS class load using composer?

I have a class file Settings.php that loads an ini file and assigns the content to a constant for global access and reducing clutter. The class file contains the logic for loading the settings and ...
theking2's user avatar
  • 141
2 votes
2 answers
325 views

Is it okay to use Dependency injection only because of unit testing?

I have a class that has dependencies that I know are not going to change. class ConversationFinder { public function __construct( protected Conversation $conversationDbFinder = new ...
Ghassan Barghouti's user avatar
1 vote
2 answers
216 views

Best way to protect action links from CSRF

An application has a multifactor login. The user logs in with its e-mail and password, and then the following screen asks for a one time password received via e-mail or generated by a mobile app. In ...
user2190492's user avatar
0 votes
0 answers
54 views

How to group together common allowed descendants of a vertex in a tree data data structure?

I created an abstract class to represent a vertex in a tree structure. Later, a requirement was introduced where certain types of vertices are not allowed as descendants of certain other vertices. So ...
Cave Johnson's user avatar
1 vote
1 answer
394 views

Languages with PHP-like traits?

PHP have what it calls "traits" which despite the name is not like traits in Rust, Scala or other languages. In many other languages with support for traits, a trait create a is-a relation. ...
Fred's user avatar
  • 489
2 votes
3 answers
212 views

Organize and maintain a lot of cron jobs

I am working on a fairly large project written in PHP (Yii2) in which we are increasingly using cron for background tasks, such as generating caches, reports, etc. We have started to move the hourly ...
MKMarek's user avatar
  • 29
1 vote
1 answer
208 views

Why does PHP have int and float data types?

I have realized that PHP can treat string variables as numbers (as long as int or float values are stored in the string variables), for example: <?php // Declaring two int numbers and one float ...
user21403677's user avatar
0 votes
3 answers
1k views

Is it code smell to make an abstract child class override a parent method which only calls its own abstract method

Is it code smell to make an abstract child class implement a method, which overrides a parent method, whose only purpose is to call another abstract method? I want to make sure that anyone who ...
Cave Johnson's user avatar
0 votes
1 answer
95 views

How to refactor parallel inheritance tree?

I have a (php) program, which must change yearly. This program calculates tax for every year and there are sometime changes in requirements. First, the user fills their incomes, expenses, etc. Then ...
nrob's user avatar
  • 111
3 votes
2 answers
1k views

Is it good design to have a repository update multiple entities?

I'm building a web application using Laravel. I use the repository pattern as my data layer. Imagine there's some entity like Product and a product can be assigned to a ProductCategory. The Product ...
user2190492's user avatar
0 votes
1 answer
194 views

Why do the arguments in PHP's array_udiff() comparison function not always stay "in order"?

Recently I was trying to use PHP's array_udiff() function to compare a value in a multi-dimensional array with a plain old string value. I tried something like this: // E.g. $employees[0]["name&...
WackGet's user avatar
  • 109
0 votes
0 answers
884 views

Best way to check for truthy values in PHP?

In PHP, there are several ways to check whether a value is true, or similar: true === $v, only works for bool true == $v || !!$v, works with int and string, but a non empty array can also be ...
Gabriel Smoljar's user avatar
2 votes
2 answers
244 views

To maintain SOLID, should data preparation, conversion, and pre-computation for purposes of saving an object, be separate from data persistence layer?

I am facing a common situation where I am saving some values into database from a business object. I am using a relational database and usually I only need to save a few items that are part of the ...
Dennis's user avatar
  • 8,247
1 vote
3 answers
236 views

Should you reuse a PHP exception's code when wrapping it?

When catching and wrapping an exception in PHP, assuming the new exception doesn't have a meaningful code of its own, should you also use the caught exception's code value? or the default value? In ...
TravisCarden's user avatar
-2 votes
1 answer
148 views

Using Apache and PHP to provide Frontend, possible to use PHP also for backend?

I have a design question to all the programmers out there. Until now, I wrote most of my software in vb.NET oder C#, especially if I needed a Frontend. Now I would like to have a Frontend which is ...
Manuel's user avatar
  • 97
-2 votes
2 answers
63 views

How to serve customized content to each user, based on targeting criteria?

In my PHP Laravel application, I want to display special offers to users, depending on the quality of their house(s). There are 4 Models: User, House, Offer, OfferTargeting. Each User can have many ...
Tim Kohlen's user avatar
0 votes
1 answer
559 views

Validation in both controller and my service classes?

I use the Laravel framework. I've got controllers, like CustomerActivityController, and I've got a service layer with services like CustomerActivityService. Say I want to create a new customer ...
user2190492's user avatar
0 votes
2 answers
178 views

How to refactor code so that a facade class could be decoratable?

I've got a class that is a facade class (encapsulates complex-ish behaviour for reusability). It has a function called manage (the class is called Manager): function manage() { $entityBuilder = '...
pro100tom's user avatar
  • 449
1 vote
0 answers
576 views

CQRS, DDD and batch, CRUD-y operations

How to perform basic CRUD operations (especially batch) by playing with DDD and CQRS? Let's say I have a list of IDs in my controller that need to be removed (soft delete). Currently, I treat this ...
krufkojat's user avatar
0 votes
2 answers
140 views

Decisions according to environment

I am trying to convince others that the following first code snippet is bad practice and the second snippet is best practice. Bad practice: // There is only one implementation of Adapter public ...
Daniel W.'s user avatar
  • 535
0 votes
2 answers
439 views

Share data between users without a database, php [closed]

How would I create for example a live chat, where you "post" a piece of text and it is displayed to other users in a "chat room", without the need of permanently storing it. My ...
bird-dancer's user avatar
0 votes
1 answer
273 views

Why doesn't PHP support function overloading (even though it supports type hinting)? [closed]

Why doesn't PHP support function overloading (even though it supports type hinting)? For example why we can't do something like this: function foo(Student &s) { } function foo(Employee &e) { ...
paul's user avatar
  • 121
-3 votes
1 answer
64 views

Server performance and CMS scalability [closed]

I have been given the job of a colleague who has resigned and I don't know where to start. I hope you can give me some hints: It is about a CMS made from scratch (Javascript/jQuery/PHP/MySQL) which ...
ADM's user avatar
  • 97
0 votes
2 answers
911 views

How to concretize a return type when inheritance is used?

I have two repositories: class RepositoryOne { /** * @param int $id * @return ModelOne */ public function getById($id) { // Search and find a ModelOne model in the ...
pro100tom's user avatar
  • 449
0 votes
2 answers
297 views

Design patters for handling invoice "payment_status" when split payments are involved

Requirements I'm building a system with the following requirements. An Invoice can be paid using multiple Payments (e.g a customer pays the invoice in 2 installments) A Payment can be allocated to ...
Amade's user avatar
  • 109
0 votes
1 answer
174 views

Strategy pattern with implemented public method

New to design patterns so my question maybe silly. I want to use strategy pattern for returning data from a databases in the same format. Nevertheless it varies the query on the underlying database ...
Christoforos's user avatar
2 votes
1 answer
815 views

Static validator in DDD value objects

I have a value object to hold a user id number as a string. This number has a unique format throughout my domain. So, it's being validated inside the object during instantiation and an exception is ...
Pavi's user avatar
  • 131
1 vote
2 answers
411 views

QR Code Scanning with location check

I would like to make an order-system with QR-Codes which is online. How I imagine it to work: A customer visits a restaurant. There is a QR-Code on his table which takes him to a public webpage where ...
rbnpts's user avatar
  • 19
3 votes
4 answers
2k views

How to store a password so that it can be passed to another site/service which is expecting a plaintext input

I am developing a website and I would like to allow users to use XMPP for live chat. I would like users to have the option use an existing XMPP account if they wish and store their XMPP username and ...
Leo Grün's user avatar
0 votes
2 answers
66 views

Getters and (static) processor vs multiple processor wrappers

I've got a class which stores two data series like so. I need to do some complicated processing on each of these arrays, but for now we'll just get the average of each data series. I could either do ...
Tim Hitchins EkkoSense's user avatar
1 vote
1 answer
103 views

What is the best approach to use a common variable in multiple method in a request in laravel [closed]

I have a $c variable that is calculated at the beginning of the request. After calculating this several nested methods use it as a part of their job. Is it better that I pass down the $c variable to ...
mehrdadep's user avatar
  • 121
3 votes
2 answers
167 views

When is it Counterproductive to Separate PHP and HTML

Understanding that it is less load on the server to not have to parse HTML, when does it work the other way, as far as server performance. The majority of my Web sites are database-driven - often the ...
RationalRabbit's user avatar
40 votes
7 answers
10k views

Why do library developers deliberately break existing code?

Today, I updated ZBateson\MailMimeParser the PHP e-mail parser library from 1.x to 2.x. Soon enough, my PHP error log started filling up with errors. Noting where it happened, I found out that it had ...
user16508174's user avatar
-1 votes
1 answer
512 views

Adapter pattern for formatting third party API responses

I've been refactoring some of my procedural code to OOP, and I'm wondering if using the adapter pattern is overkill in this case. Basically, I created a Order class. All class properties are a field ...
Matheus's user avatar
  • 11
0 votes
2 answers
366 views

How to measure the benefit of replacing big parts of the HTML DOM vs doing a new fresh request?

I am looking for a method to measure the time difference between: the time it takes to load and completely reach TTI for example.com/page-B given that example.com/page-A is loaded. the time it takes ...
Álvaro Franz's user avatar
2 votes
4 answers
504 views

Would this violate the Liskov Substitution Principle?

Say I have a set of objects from an "old system" that I want to convert to a newer set of corresponding classes. Each specific class has its own way of being converted. So I have this: ...
Jeto's user avatar
  • 169
0 votes
1 answer
65 views

"Subtractive" behaviour extension vs overriding a function completely - what are the pros/cons?

Lets imagine some vendor code that we want to extend on our project level protected function getDefaultFormClasses() { return [ new FormClassA(), new FormClassB(), new ...
Jim Panse's user avatar
  • 398
0 votes
1 answer
123 views

How to prevent mutual dependencies when implementing database relationships

To explain the problem imagine you have two entities User and Group. The OO implementation has two classes UserModel and GroupModel. UserModel should have a method getGroups() (returning instances of ...
Sebi2020's user avatar
  • 101
1 vote
1 answer
579 views

Is it a bad idea to put each class method in its own file? [closed]

We have an existing project that has grown very messy and confusing; our classes are huge and difficult to read. Our boss wants us to break all of our methods out of the classes and into separate ...
Tim's user avatar
  • 11
3 votes
3 answers
223 views

Build once or twice: how to synthesize advice from PHP's Composer package manger manual and Continuous Delivery

Authors such as Dave Farley advise us to "only build packages once", so that we can "be sure the thing we’re deploying is the same thing we’ve tested throughout the deployment pipeline&...
bdsl's user avatar
  • 2,734
3 votes
2 answers
261 views

Visitor pattern applicable ? - Applying rules to a list of registrations

I have a list of Registration's, on which I need to apply a set of rules to each individually. Rules can be a single Rule, or a sequence of rules, representable by a tree. One rule is a ...
Sheph's user avatar
  • 139
-2 votes
1 answer
457 views

Structure project by inheritance?

The usual approach is to do what libraries do: group your (single file) classes by component where folder = namespace, right? That makes sense for code that is mostly meant to be used by other ...
DanMan's user avatar
  • 105
0 votes
1 answer
46 views

Improve performance of single tenants on shared server

I'm trying to improve the performance of our server. We have 1 server with around 25 tenants, each tenant has it's own application instance and database. There are no performance issues, until, each ...
RiesvGeffen's user avatar

1
2 3 4 5
41