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

PHP Constant Naming Convention

I have an interface like given below in which hundreds of messages are defined. Is this constant name is fine according to the php coding conventions? I have searched in the internet, but could't find ...
-1
votes
0answers
9 views

PHPStorm + xdebug didn't work

Xdebug is configured. Xdebug helper installed. Validation in PHPStorm is OK. When start a session with "Breake at first line ..." enabled, it stops on the first line of index.php - it is empty, but it ...
-4
votes
2answers
55 views

What industry alternatives exist for “set” in an API assigning values [on hold]

I'm creating a library using PHP. I prefer to avoid making properties part of the public API. class Something { private $value = ""; // getter public function value(): string { ...
0
votes
1answer
38 views

PHP - Return array of file names from multiple folders [on hold]

I have below two folders Table and Text, which contains below files: Rules - Table - regexTextReplace.php - textReplace.php - Text - regexTextReplace.php - textReplace.php - ...
2
votes
2answers
75 views

Server-side script to handle many near-simultaneous incoming XMLHttpRequests

I am building my own analytics platform, which I want to work like this... A JS script in each of my webpages collects data about users' clicking behaviours and sends that data to a PHP (or other ...
1
vote
0answers
29 views

Determine array of objects collective identity and be able to inspect it

I have an array of objects and I'm trying to see, through each request, whether or not a new member appeared in my collection. The way I currently do it is, I require each member of the collection to ...
0
votes
1answer
20 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(...
0
votes
0answers
59 views

Parsing custom if statement input in PHP

I'm working on a feature where users can get data based on the if statement they write. The if statement looks something like the excel's conditionals. Basic syntax: IF ( lhs == rhs, ifTrue, ifFalse)...
0
votes
0answers
11 views

Integrate different sources of notifications in a Laravel web app

Notification Integrations I am struggling a bit with how to design a flexible/dynamic notification system in my Laravel 5.8 web application. Consider that I have something called streams. Each ...
1
vote
0answers
35 views

Web Service returning serialized helper objects

I had the idea to have a route in my REST API that returns serialized (PHP) helper objects. The client code then can use those objects to format some complex JSON structures for the next request. When ...
2
votes
6answers
111 views

How can I change my code to display information about failure of creation of a value object, when I want to process an array of such objects?

Consider class Crate that is a value object. Crate represents a valid 3-dimensional box. In constructor I validate the given parameters, and I throw an exception, if supplied dimension parameters ...
0
votes
0answers
52 views

IS good idea to use constants instead of raw literal strings and when is a bad one? [duplicate]

Usually when I code in PHP I try to avoid using literal strings in cases such as: define('IMAGE_DOWNLOAD_PATH','./data/images/'); define('IMAGE_FILENAME_PREFIX','myapp_'); $url="http://exaple.com/...
0
votes
1answer
66 views

Api limit access to subscribers only

I have a vanilla php api(on a vds) and I want to make data coming from that api available to a few clients that are using a python app that's also written by me. That python app is running on my ...
0
votes
1answer
32 views

MVP where to set Content-type header?

I'm having some problems with deciding where to set the content-type header in a vanilla mvc framework. Should i add it inside the controllers method: class ApiController extends Controller{ ...
0
votes
1answer
80 views

Avoiding downcasting in PHP

This is a theoretical problem that bothers me. Let's say we have following, simplified structure: interface ParagraphInterface {} interface ParagraphGroupInterface { public function ...
0
votes
0answers
23 views

Multitenant setup with master account

I would like to make a SaaS which would be a multitenant system. Development is done in Laravel, which is less important. What I would like to know is how would you handle having a master admin ...
2
votes
4answers
438 views

Instanceof code smell

The use of instanceof might be a code smell and I am in front of the following code which seems ok. Would you consider that instanceof should not be used in such case? What would be the pattern to use?...
0
votes
0answers
58 views

Laravel web middleware on API routes

I am using Laravel 5.8 and am designing an API. I was wondering if there is a setback to using a web middleware in API context? I have created a new middleware for API routes which uses sessions, ...
0
votes
1answer
76 views

Refactoring – Removing switch statement [duplicate]

There is a base class Product having all the generic properties and methods which a product should have. abstract class Product { public abstract function process(); } Now, These are the few ...
1
vote
3answers
123 views

What considerations should I mind when designing methods or functions that take in a lot of parameters?

What considerations should I mind when designing methods or functions that take in a lot of parameters? A lot meaning over 4 but less than 10. Example, I am debating whether to pass in an array like ...
0
votes
0answers
35 views

Optimal database design for different types

I am trying to build an application, where users can create unlimited "parsing fields", that will contain either a: String Array id | name | type ------------------- 1 | name | string 2 | table |...
1
vote
2answers
94 views

Best practice for a group of similar functions

I’ve built a small little library that I think really aids in PHP development. It makes secure by default database transactions, makes cURL requesting anything easy (including files), and it has a ...
1
vote
1answer
132 views

Do complex return types in interfaces exist in programming?

I believe, for PHP, that I've found the worst culprit when it comes to bad code: not being able to declare (return) implementation details through interfaces. This makes it unpredictable to see what ...
0
votes
1answer
38 views

Should i use a separate droplet(DO) for the API?

I have a little app(PHP) that uses data from a third party. That data is processed constantly and saved into a database. And now i want to create a RESTful API to allow access to that data. Should i ...
0
votes
1answer
48 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. ...
-2
votes
1answer
50 views

How to check last release of php using php [closed]

Let's say I have some project on php. One of its functions should be to check whether the latest version of php is used on the server. For example, for security reasons. There are no problems to use ...
0
votes
0answers
19 views

Merging php and Nodejs docker images for a developer ready php image used for php application development and CI

For my application I need to provide an image that will be used to develop and release my php application. As well know a php application for the frontend required tools as well such as gulp webpack ...
1
vote
0answers
55 views

PHP: Binding PDO result values to class properties [closed]

I am new to PHP and am trying to figure out the best practice with respect to binding column values to properties in a class. The column names in the database are not ideal and I would like to extract ...
0
votes
2answers
102 views

PHP MVC - One view class for all controllers vs a view class for each controller

I am creating an MVC inspired PHP framework, mainly for learning purposes. I basically have the framework created and am building an app on it and improving the framework as i go along. I am still ...
0
votes
1answer
73 views

PHP: simple class for storing read-only data structure, array alternative

I need to share some associative data between different parts of my application with two requirements: immutability (so read-only) safety against mispelling or unavailable index inside the data ...
2
votes
1answer
178 views

How can I allow interaction between user-only modules & admin-only modules without polluting with privilege checks?

Important note: This is PHP (5.3+). PHP is stateless and everything you do dies when the request is over unless saved to a persistent storage, but if the answer provided gives me pseudo-code, I'd also ...
0
votes
2answers
92 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 ...
0
votes
1answer
69 views

Which types of objects that are instantiated inside controller's methods should be injected into the controller instead?

Consider code below MyController //MyAction //MyHandler { public function processRequest() { // ... $myObject = new MyObjectClass(); $myObject->methodCall(); ...
0
votes
3answers
107 views

What to do when a class' method depends on another class' method to pass an array with a certain key?

To cut a long story short, assume I have a Register, a Provider and a Generator class. In my Register, I have the addItem method that allows me to add items to a collection. The Provider's job is to ...
2
votes
2answers
203 views

What is wrong with writing web applications in a way that merges repository layer with view and with controller in the same file?

is there anything wrong with writing code in a way that merges view, repository, controller in the same file? i.e. global $db; // or $db = DBSingleton::get_db_instance(); // or global $container; $...
1
vote
1answer
152 views

How does machine learning learn? [closed]

I'm new to Machine learning or Ai but I have been a developer for almost 10 years. I have a news aggregator application that grabs and save articles from news websites, And I have developed an ...
0
votes
1answer
76 views

Structuring PHP classes that need to return multiple objects

I am trying to plan out php class structure for an order processing project. I've used classes before but I'm still not an expert on OOP yet. I've been searching for hours and can't seem to find the ...
0
votes
0answers
29 views

Wrapper class organization

I have Auth class which I am calling at one place in the code: $this->auth = new Auth($this->options); Now, the Options is the class containing things like host, port, username, pass... and is ...
0
votes
4answers
123 views

Could you please recommend an approach on converting non-unique field to a unique field?

On our prod db we have two tables: companies invoices Relationship: A company has many invoices An invoice belong to a company The invoices table contains duplicate invoice_number for each company. ...
0
votes
2answers
56 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
3answers
100 views

Can I make other developers aware that they can define certain functions for extra-functionality even if they're not required?

The language is PHP. I have the certain, in my opinion, code smell, it doesn't feel right: In my controller class that ingests objects of the same type (interface, it's ViewBlockInterface), I check if ...
4
votes
3answers
373 views

What to do when interfaces force me into violating the single-responsibility principle?

(The code I'd have to post is huge, I'll resume to just function names) I'm currently faced with the following issue on my project: I have a "each module from this framework can have a small view ...
2
votes
1answer
74 views

How to implement acquaintance and aggregate as described by the Gang of Four

Is the following implementation in PHP correct? I focused on what they say about the lifetime of dependencies: “Aggregation implies that an aggregate object and its owner have identical lifetimes.“ ...
0
votes
1answer
163 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 ...
3
votes
3answers
190 views

A better way to generate plaintext content

I'm generating plaintext emails with heavily personalized content: depending on various factors, sections or sentences need to be inserted, left out or phrased differently and placeholders need to be ...
0
votes
3answers
205 views

Separate Function or Same Function for similar functionality (SRP vs DRY)

I'm trying to decide the best course of action based on two design principles that seem to be conflicting with each other: "a function should only do one thing" (SRP) and "don't repeat yourself" (DRY)....
0
votes
0answers
60 views

Allowing a user on one page to be able to cause an event on another

I would like to allow a set of users to be able to submit a form on one page, and then it would cause an event to trigger on another page. For example: Submit Page: Includes the form, the user ...
1
vote
3answers
186 views

URL friendly id from DDD entity id

I am currently learning DDD and having a hard time wrapping my head about how to implements URL friendly ids for a web application. From my knowledge, in DDD it is common practice to use UUID as ...
2
votes
1answer
120 views

PHP - Dynamically apply parsing rules to text, and save to dynamic fields

OK, so I have been at this problem for the last few days, and I must admit - I am stuck. I am trying to make a web application, where users can upload documents or send inbound e-mails. Each ...
1
vote
1answer
141 views

PHP - Designing a rule based parsing engine

Dynamically apply methods/"rules" to documents I hope someone here can help me/guide me in the right direction. I am currently creating a web application, where users can import a text file, and then ...