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

Strange Behavior of PHP Web API

Firstly, I have 1 web application and 1 android apps. For authentication, we are using an API provided by our client. This is actually my first time working with an API. The authentication works fine ...
0
votes
1answer
148 views

Create object just to call a function in PHP. Is it as bad as I think ? How to redesign?

I was recently hired in a company and I have been asked to help writing an API that was left unfinished. I do not have much experience yet so I am never too sure what are good coding practices. This ...
24
votes
9answers
6k 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 ...
15
votes
6answers
5k 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, ...
0
votes
3answers
139 views

Should it be considered a BC break to return clone instead of new self?

(This question applies to the equivalent code in both Java and PHP) I have a class like this: class Foo { private int $bar; public function __construct(int $bar) { $this->bar = $...
3
votes
2answers
191 views

Not confident about pre/post conditions in LSP

I have some doubts about practical ways to violate the Liskov Substitution Principle regarding pre and post conditions. I created examples in which I believe the first child respects LSP and the ...
1
vote
1answer
264 views

RabbitMQ Consumer Architecture

I have been investigating using RabbitMQ for a publish/subscribe pattern across micro-services where aysnc calls are appropriate but I am having trouble understanding some concepts and could not find ...
1
vote
1answer
146 views

How can I deal with objects that might or might not implement some interfaces in PHP?

I have a collection of view objects. Each one of these objects must 100% implement the following interface: /** * Interface that each base ViewBlock object must implement. */ interface ...
1
vote
1answer
95 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 ...
0
votes
0answers
50 views

Ajax with interval vs WebSocket

I am currently developing a script for real estate which tries to find a match between your products and your clients needs. So I need to give the user a notification whenever a match is found, I am ...
-1
votes
1answer
68 views

RuntimeException or DomainException or LogicException in loader function?

Assume I have module of classes: EntityLoader loads some entity by id. EntityValidator checks preconditions, input data before saving changes. EntityUpdater saves changes. EntityLoader has method ...
3
votes
3answers
290 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 ...
0
votes
0answers
19 views

Filter Gallery Images based on dropdown selection values

I currently making a "visual plan builder" with php-mysql, ajax and jquery Using multiple layers (z-index) I generate a visual plan with the following dropdown list values: Base Product - ...
-1
votes
1answer
59 views

How to test and what kinds of test to write for Request Handlers that use Repository layer?

Consider class below: class FillTestBySerialHandler { /** * * @var FillTestBySerialRepository */ private $fillTestBySerialRepository; function __construct(...
13
votes
1answer
490 views

Accessing i18n objects from different scopes

I have been building a personal framework of mine which started off as a way to learn the MVC pattern and has progressed now into something that I like more than most frameworks out there (which is ...
1
vote
3answers
17k views

Simple real-world PHP OOP example?

I'm trying to learn PHP OOP, but when I've followed tutorials, all the examples seem to involve things like: class Human { $_sex; public function setSex($sex) { $this->_sex = $sex;...
1
vote
1answer
153 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
1answer
52 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 ...
0
votes
0answers
22 views

Design pattern for duplicating lines of code in control structures [duplicate]

on my website I have a multi-page form where user can pass some data on each view, but user can also save a draft on specific step(in my example 1-4). My service has a dispatch method. Based on step(1-...
1
vote
4answers
192 views

Is having 3 return types for a function, in order to facilitate error handling a bad idea?

I have a function which returns either true/false, each return plays nicely with the function name: isOnline, however, there are cases in which I want to throw an error inside of it. Maybe the status ...
-1
votes
1answer
58 views

How to write package for two frameworks

I'm developing a package for Laravel & Lumen in the same code base, but I encountered some problems. Well, in the beginning, I thought it could have the same code and work for both frameworks, ...
54
votes
11answers
11k views

Is there a general solution to the problem of “sudden unexpected bursts of errors” in software?

Let me explain what I mean. I have made a complex, highly polished over years PHP framework/library for my own use. I very aggressively log the smallest notice and immediately deal with it as soon as ...
0
votes
2answers
99 views

PHP class inheritance in variable depths across systems

I have a project where I develop a software which consists of a CORE which is in a separate project, developed separately, and a CLIENT which's base is the CORE but adds to the functionality with ...
0
votes
1answer
692 views

How to setup REST API in Codeigniter 3.0

I am creating the REST API using codeigniter. I downloaded this library and installed in my application. It works great! https://github.com/chriskacerguis/codeigniter-restserver But I have an doubt. ...
0
votes
1answer
239 views

Integrate react app with php app

I have an old php web application, with very bad code. While a lot of it just has html and ajax calls in the, the wrapper is still php. I want to develop the new modules in react, and slowly replace ...
-1
votes
2answers
242 views

PHP preg_replace() vs filter_var()

I have seen numerous posts on this subject but none really answered my questions. I have some user input that is inserted into my DB and displayed back to the user later. Before inserting it into the ...
0
votes
1answer
132 views

Memory Usage for Website

I have been working on a project and Im hoping to get a gauge on possible performance issues before I put it in any production environment. Currently on my local machine Chrome's task manager says I ...
2
votes
0answers
67 views

I'm trying to write something that will fill out an Australia Post Declaration Form [closed]

I've got basic proficiency in PHP, JavaScript, html, and SQL. I also use Postman little a bit. I hope a solution to my problem can be found within those skills, but I'm willing to learn a new language ...
0
votes
1answer
706 views

The finer points of HMVC

I'm new to HMVC and whilst tutorials are great about dealing with the overall details of keeping modules separate and only letting controllers communicate, they aren't so great at explaining the ...
0
votes
1answer
5k views

Reporting Solution in PHP / CodeIgniter - Server side logic vs client side

I'm building a report for an end user. They would like to see a list of all widgets... but then also like to see widgets with missing attributes, like missing names, or missing size. So i was ...
4
votes
1answer
1k views

Why place Composer in separate docker container?

Note: this question is not strictly PHP-oriented, since both Docker and Composer can be easily used outside of the PHP ecosystem (although such cases would be rather rare IMO). In one of the projects ...
0
votes
1answer
367 views

How to handle optional dependencies in php?

At my Job I'm currently on refactoring a very old php CMS. By now, "code handling" was done by simply copying the whole thing and modify it to fit whatever was needed for this job to be done (actually ...
0
votes
0answers
38 views

How to name multiple entities returned from a Query Handler?

I've got the following flow: HTTP API is exposing data from 2 database tables that are combined into one JSON structure. We're implementing this using CQRS - splitting the reads from multiple tables ...
2
votes
0answers
163 views

How to handle a bunch of nested ValueObjects?

I'm writing a PHP web application (or actually a Symfony module). One part of it is a nested structure of ValueObjects (meaning: they are immutable and have to be validated on the creating). Such an ...
-4
votes
1answer
57 views

How could I redefine a new type for subclass

I'm trying to represent some entity. LineProduct A line holding a quantity of product and a Product entity LineProductBlank A line holding a quantity of product and a ProductBlank entity Product ...
-8
votes
1answer
79 views

Are the stone-dead PHP mailing lists really how PHP developers and the PHP community communicate? [closed]

I've been looking at this for a long time: https://news-web.php.net/ Almost every single mailing list has the last messages sent to them in the year 2000-2003. That's 17-20 years ago! It would be an ...
0
votes
1answer
104 views

Could this be considered a valid State GoF Pattern implementation?

For teaching purpose, I would like to create a simple implementation of State Pattern using PHP 7.4. So, I've tried to create a simple "document state machine" starting with Draft, sending to review ...
0
votes
1answer
89 views

Using the objects retrieved at the time of request validation

I hope the question title already answers the subject here. Lets say I have a number of ids that needs to be validated in a request. Example: request uri: [POST] /album/{album_id}/song Request ...
0
votes
2answers
96 views

Instantiating a reference loop

For the following use case I tried to use (self-)reference loop. Use case A round based game what changes difficulty level after each round. The set of difficulty levels is fixed size. After each ...
2
votes
2answers
178 views

Should I rewrite a large portion of code to make it more organized for my web application? [closed]

I've been working on a LAMP application(a social network), and am about 4000 lines of code in, and have a working prototype. I learned PHP this way, and thus it isn't programmed very well, and am now ...
0
votes
2answers
157 views

For a very long lived PHP web application project, is custom (self made) framework better than (open source) popular frameworks?

For a project that's going to live/used/maintained by the developer for a very long time (ex: 20-50 year); Is custom (self made) framework better than (open source) popular frameworks? Basically my ...
1
vote
1answer
130 views

Static data reuse

I'm going to describe the situation first and ask questions in the end. I need to validate a scalar value using the Symfony Validator component. The value is an associative array. Now I have defined ...
-6
votes
1answer
77 views

What is the best option between buying, building from scratch or implementing an open source ERP? [closed]

I was required to do a medium ERP with the inventory, Bill of Materials, and production modules. However, I do not know how long it would take me. I am calculating three months for the analysis and ...
5
votes
2answers
866 views

Dependency Injection & In-class Instantiation | Practical Limitations

Dependency Inversion is Good Inversion of dependency is good, it: Simplifies unit-testing Reduces coupling, allowing software components to be used interchangeably Keeps instantiation logic for a ...
13
votes
6answers
10k views

DDD Injecting Services on Entity Methods Calls

Short format of question Is it within best practices of DDD and OOP to inject services on entity method calls? Long format example Let's say we have the classic Order-LineItems case in DDD, where ...
3
votes
1answer
102 views

Performance: Creating duplicate file

I have a Web server (Local) and File server(Remote). I need to create a duplicate of an xml file in the same location with different file name in the File server. The size of the file is random, but ...
0
votes
1answer
99 views

Design leading to break contravariance. How to avoid it?

I have a Converter which use a Resolver to determine which Factory to use when converting a Resource to a Entity. To do so, I need to be sure that the Factory has a createFromResource method. The ...
-2
votes
1answer
53 views

Why does DateInterval lack weeks, quarters/seasons, as well as decimal/float versions of each property?

This has puzzled and frustrated me for years: https://www.php.net/manual/en/class.dateinterval.php y Number of years. m Number of months. d Number of days. h Number of hours. i ...
1
vote
2answers
293 views

Documentation of interfaces

I know how to document a function: /** * Prints a greet message to the web page */ function greet() { echo "Hi!"; } Or describe the usage of a variable: /** * @type string $name The user's ...
-2
votes
1answer
147 views

SOLID way to handle user input error (I18N & error context problematic)

Disclaimer : I come on this topic after it has been recommended to me on my previous closed SO topic (see closed one : https://stackoverflow.com/questions/64338968/how-to-effectively-manage-a-large-...

1
2 3 4 5
41