Quantcast
Channel: Active questions tagged php - Software Engineering Stack Exchange
Browsing all 31 articles
Browse latest View live

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 db. return new ModelOne(); }}class...

View Article



Why is using 'final' on a class really so bad?

I am refactoring a PHP OOP legacy website. I am so tempted to start using 'final' on classes to "make it explicit that the class is currently not extended by anything". This might save lots of time if...

View Article

Loan Amortization Schedule - Precision and rounding

I have been playing around making amortization schedules in PHP. My php.ini currently has the precision set to 14. I understand going into this that there will be rounding errors however I am hoping to...

View Article

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. So if class...

View Article

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

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 I...

View Article


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 that...

View Article

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 Conversation,...

View Article

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...

View Article


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...

View Article


Safety of magic setters in PHP

I don't know how in else languages, but in PHP seems to me that they are very unsafe way how to set value of any member variable - because one setter cannot easily validate input for many variables...

View Article

frontend server obtain data from backend server, or frontend server return...

I'm currently learning how to separate frontend server and backend server. However, i'm not sure which approach should i take between the twoFrontend server obtain data from backend server and adjust...

View Article

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

The problemLet's assume such scenario:List of IoT devices (one model?)Each list item has (among other fields) a type fieldDepending on the value in the type field, device may report different values...

View Article

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...

View Article


Repository Pattern: Doctrine2 vs Microsoft Entity Framework?

I have been using Symfony2 with Doctrine2 for some years. I have recently started using Microsoft's Entity Framework with MVC5. From my Symfony2 experience I understand that a repository's job is only...

View Article

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 activity...

View Article


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...

View Article

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 the...

View Article


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}/songRequest...

View Article

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...

View Article

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...

View Article
Browsing all 31 articles
Browse latest View live




Latest Images