Skip to main content

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
-2 votes
1 answer
79 views

PHP secure storage for sensitive document uploads [closed]

I need help deciding how to securely store sensitive docs uploaded via a PHP script. I realize I'm not personally qualified for this task (if I was I wouldn't be asking this question) but need to know ...
Chris P's user avatar
  • 11
0 votes
1 answer
142 views

How to share transaction across multiple repositories in DDD?

We are trying the Domain Driven Development (DDD) while working on a project. We've got a Product aggregate. We've got a ProductRepository to load/save Products. We've also got a Timeline aggregate, ...
user2190492's user avatar
0 votes
1 answer
131 views

DTO Interfaces naming convention in PHP

It might be that my question would sound a bit stupid but I would like to find the best way for naming my DTO interfaces. In my PHP application I have following DTO types: Simple (which contains a ...
Viacheslav Ravdin's user avatar
4 votes
2 answers
261 views

Interface + Trait vs Abstract Class

While developing my application I faced an interesting situation: I have multiple DTO's which are almost identical in terms of methods, only properties are different. For example I have AccountDTO ...
Viacheslav Ravdin's user avatar
1 vote
1 answer
151 views

DTOs and Single-responsibility principle

I'm developing a PHP application and trying to understand DTOs in context of single-responsibility principle. Being more specific, is it a bad practice having helper methods like toArray(), getValue(),...
Viacheslav Ravdin's user avatar
-3 votes
1 answer
92 views

Mock an API for development purpose (no testing)

If I want to implement a connection from my software to an API, which is documented but not accessible yet, what is a common way to imitate the API until it is available? My first idea was to mock the ...
harrow's user avatar
  • 111
0 votes
1 answer
180 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
169 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
  • 237
2 votes
2 answers
367 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 ...
user avatar
-1 votes
1 answer
158 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 ...
user avatar
0 votes
2 answers
285 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
1 vote
3 answers
296 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
194 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
  • 139
3 votes
2 answers
489 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
266 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
58 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
556 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
3 votes
4 answers
351 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
  • 39
1 vote
1 answer
225 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
2k 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
100 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
2k 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
219 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
1k 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
260 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,257
1 vote
3 answers
279 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
170 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
66 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
654 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
185 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
614 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
141 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
578 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
288 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
68 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
1k 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
316 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
189 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
907 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
455 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
67 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
126 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
188 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
643 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
374 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
531 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
66 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
  • 408
0 votes
1 answer
132 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
2 3 4 5
42