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

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

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

View Article

Help in writing more generic code

I'm doing a php MVC project using code igniter. I have two models, a and b.Each class contains four functions (insert, delete, update and view) and their implementations are almost the same with each...

View Article


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

View Article


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

View Article

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-restserverBut I have an doubt. As...

View Article

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

View Article


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

View Article

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 simply take in...

View Article

How to read large XML files efficiently

I have a large XML file (about 75,000 lines) where I have to build a catalogue (houses) from. Building the lists works fine, but now I have a problem.The catalogue should have a detailed presentation...

View Article

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

View Article



Naming classes, methods, functions and variables [duplicate]

There are 3 important naming conventions:with_underscoresPascalCasedcamelCasedOther variants are not important because they are not commonly used.For variables it seems that the one with underscores is...

View Article
Browsing latest articles
Browse All 31 View Live




Latest Images