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
1 vote
0 answers
118 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 ...
0 votes
2 answers
126 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 ...
0 votes
1 answer
82 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 ...
  • 111
1 vote
2 answers
349 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 ...
0 votes
0 answers
35 views

Mapping complex data/arrays to a standard format (normalizing data)

I am currently building an application that receives inbound XML files from a third party system. These XML files represent different types of orders in the sending system. These can for example be: ...
0 votes
1 answer
83 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&...
  • 109
0 votes
0 answers
71 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 ...
0 votes
0 answers
44 views

Long polling and resource use

I've been looking at various techniques for pushing data from a server to a Flutter Web app, and Websockets and SSE (Server-Sent Events) are unfortunately out of the question. So, I thought about ...
  • 405
2 votes
2 answers
154 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 ...
  • 8,089
1 vote
3 answers
132 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 ...
-2 votes
1 answer
73 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 ...
  • 97
-2 votes
2 answers
52 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 ...
1 vote
1 answer
362 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 ...
0 votes
2 answers
156 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 = '...
  • 449
0 votes
0 answers
318 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 ...
0 votes
2 answers
136 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 ...
  • 535
0 votes
2 answers
190 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 ...
  • 23
0 votes
1 answer
190 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) { ...
  • 121
-3 votes
1 answer
49 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 ...
  • 97
0 votes
1 answer
142 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 ...
  • 449
0 votes
2 answers
177 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 ...
  • 109
0 votes
1 answer
116 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 ...
2 votes
1 answer
479 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 ...
1 vote
2 answers
291 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 ...
  • 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 ...
0 votes
2 answers
63 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 ...
1 vote
1 answer
81 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 ...
  • 121
2 votes
1 answer
122 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 ...
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 ...
-1 votes
1 answer
219 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 ...
  • 11
0 votes
2 answers
306 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 ...
2 votes
4 answers
429 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: ...
  • 169
0 votes
1 answer
53 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 ...
  • 326
0 votes
1 answer
95 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 ...
  • 101
1 vote
1 answer
214 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 ...
  • 11
3 votes
3 answers
199 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&...
  • 2,155
3 votes
1 answer
181 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 ...
  • 139
-2 votes
1 answer
381 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 ...
  • 105
0 votes
1 answer
43 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 ...
4 votes
2 answers
315 views

Is there a canonical definition of SPA or is SPA a broadly agreed-on architecture with fuzzy edges? [closed]

Is there a canonical definition of SPA which would exclude the software architecture model described below? I'm working on an app with a new web-architecture model (new to me, at any rate) which has ...
2 votes
4 answers
749 views

Do all dynamically typed languages not support function overloading?

I have noticed that JavaScript and PHP and Python do not support function overloading. Do all dynamically typed languages not support function overloading? If the answer is yes, then why is that?
  • 55
2 votes
3 answers
275 views

Is it best practice to always try to return a minimum number of rows from the database?

First-time poster so please be gentle :) I have a rather large table in my database (MySQL in case it matters) that holds lat/lng values of certain points of interest around the world (table name: ...
  • 131
-1 votes
2 answers
331 views

PHP Design Pattern, separation of concerns: should the Controller make a new HTTP request to the API?

I'm having a huge doubt on how to connect the front-end of my application to its back-end. So my application has a single entry point where all requests go. The request is dispatched to a controller, ...
2 votes
2 answers
130 views

Use old legacy application code from new application

If you have a big legacy application (big ball of mud), lets call it MudApp. If you then create a new application to make us of new technology and to make a new good looking frontend because that was ...
  • 59
15 votes
6 answers
10k views

Should I use DATE or VARCHAR in storing dates in MySQL?

Simply put, I have date and time attributes on an Orders table. The data types for these attributes are MySQL's DATE attribute. But everytime I echo the date and time in PHP it just gives me a string, ...
  • 215
34 votes
9 answers
11k views

Is it good practice to echo PHP code into inline JS?

I'm new to PHP and JS and I'm currently working on a gym management web app for our project in school. I'm adding a bit of QR functionality that sees if the user is eligible to enter the gym or not by ...
1 vote
1 answer
388 views

In which layer should I load views on a Clean(ish) architecture?

I am trying to organize my architecture following the clean architecture while using some common practices/frameworks. I'm writing in PHP, but have no problem with other languages. The flow of my app ...
1 vote
1 answer
238 views

Is this correct adherence to Liskov Substitution Principle?

I used to have a base object with subtypes behaving in all but the same way -- the difference being in their render methods. This base class defined a default render method, overridden by Some ...
-2 votes
1 answer
71 views

Authentication solution for custom PHP-based API

Here is description of my app I'm working on. On the client-side (index.html) a user can interact with a data. When he needs to call a server operation for example reading or writing a file on the ...
  • 99
3 votes
3 answers
299 views

Caching model objects to avoid multiple SQL commits

In decomposing a monolithic web application into smaller services and by following the Strangler Fig pattern, I'm in the middle of a problem for which I can't find a practical solution. There is a web ...
  • 336

1
2 3 4 5
41