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
2 answers
150 views

In PHP, trim() exists. By default the second parameter is " \n\r\t\v\x00" I wish to introduce my own version which doesn't deviate far from the core functionality: // Trim whitespace in ...
MonkeyZeus's user avatar
3 votes
3 answers
235 views

I'm trying to implement a heartbeat feature for offline tracking that just sends an offline message to the server once the web browser app (Laravel-based) is offline. Ideally it will ping the app's ...
meowyn0316's user avatar
3 votes
1 answer
194 views

Imagine I got user which might be either author, administrator, reviewer An author have relation on book that he wrote. An administrator have relation on banned user (we track which administrator ...
Vincent PHILIPPE's user avatar
1 vote
1 answer
152 views

I am building a website that uses a recommendation system. Users submit a form which is sent to the backend for the recommendation logic calculation; the recommendation response is sent back to the ...
Leksa99's user avatar
  • 19
2 votes
1 answer
200 views

I have an interface defined as follows: interface MyInterface { public function setMyMethod(int $a); public function getMyMethod(): int; } And I have a class that widens the parameter type: ...
Joao M's user avatar
  • 131
-2 votes
1 answer
103 views

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
393 views

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
443 views

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
315 views

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
222 views

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
146 views

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
231 views

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
195 views

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
408 views

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
251 views

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
339 views

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
524 views

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
0 answers
231 views

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
596 views

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
327 views

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
70 views

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
715 views

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
  • 509
3 votes
4 answers
504 views

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
258 views

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 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
113 views

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

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
240 views

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
2k views

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
288 views

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,267
1 vote
3 answers
344 views

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
195 views

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
73 views

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
745 views

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
205 views

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
662 views

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
156 views

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
  • 555
1 vote
2 answers
655 views

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
310 views

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
77 views

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

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
351 views

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
211 views

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
1k views

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
502 views

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
3k views

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
72 views

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
155 views

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
223 views

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

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
2 3 4 5
42