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

Why does php not allow to decrease visibility of class properties and methods in the inheriting class?

Please consider the following code: class baseclass { public $hideme; public function getit() { return $this->hideme; } public function setit($value) { $this->hideme = $value; } } ...
-6
votes
0answers
12 views

how to choose what should be the classes in my oop project

what should i choose as classes in object oriented programming. how to find what all are supposed to be the classes in my code. is it the processes or the nouns? I have a website i am designing in php,...
0
votes
1answer
53 views

Recursive speculative display list engine - computing text length across stack boundaries

Well, I've been hammering away on this for about a week now with no practical progress because I can't find mental fluidity with the concepts I'm trying to wrangle. I'm Officially Stumped, and would ...
-2
votes
0answers
62 views
+50

Understanding the scope resolution operator in PHP language

On the php manual they define the scope resolution operator as following: The Scope Resolution Operator (also called Paamayim Nekudotayim) or in simpler terms, the double colon, is a token that ...
-2
votes
0answers
22 views

Logical issue with extending exceptions in php

With PHP I am using the following class structure for exceptions: class ProjectException extends Exception { ... logical code for handling exceptions, functions that are relevant to every ...
0
votes
0answers
33 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 ...
1
vote
1answer
82 views

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 ...
1
vote
1answer
105 views

If not used in a declared transaction but used in a try…catch will rollback do anything at all?

My questions are regarding the use of mysqli::rollback. If not used in a declared transaction but used in a try...catch will rollback do anything at all? (autocommit on) If it does work without a ...
3
votes
1answer
101 views

What domain objects might I need to represent a user and users profile in a forum web application

I’ve been trying to get a firm understanding of the MVC design pattern so that I can write my own framework for implementing the back-end of a forum web application using Slim 3. In particular, after ...
2
votes
1answer
71 views

Testing Queries Themselves with Test data is a Unit test or an Integration test?

In a php project that I maintain I have a database structure without migrations, hence no way to reproduce it or make on the fly a test database. And the queries used to be performed on them are ...
-2
votes
2answers
65 views

Securely allow access to a secure area of a website with PHP

I am making a website that requires a secure area for the website owner to easily upload new content to. Because this is a relatively simple website there is no account system. I just have a URL for ...
1
vote
3answers
115 views

What is the harm in ignoring “PHP Warning: Creating default object from empty value?”

It was recommended I ask this question here as it keeps getting downvoted on Stack overflow. I am wondering What is the harm in ignoring PHP Warning: Creating default object from empty value? I don'...
2
votes
1answer
98 views

Hidden Input Fields for POST - Security

I have seen some posts on the subject of hidden input fields for use with postbut none were able to answer my question. I have a delete button tied to a user in a table. The delete button uses a ...
1
vote
1answer
53 views

What's the alternative to dictating possible methods to implement for a class instead of Interfaces in PHP?

I'm doing something wrong and I can't tell what, but I can concretely say that my problem is the fact that I'm looking at things wrongly and I reached a point you should never reach. I have a factory ...
1
vote
0answers
34 views

PHP MySQL Secure Connection - Same Server

I have some php scripts that use mysqli() to connect to MySQL which is located on the same server. I currently have the connection stored outside of my sites root and I am using include() to make the ...
1
vote
1answer
79 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 ...
3
votes
3answers
276 views

Altering Database Tables on the Fly, why is this a Bad Idea?

I recently saw a comment on StackOverflow that basically said it is a bad idea to alter tables on the fly. In my case I have a json file that is storing some information about some "products". One of ...
0
votes
0answers
24 views

Implement multiple file upload with Dropzone.js , Lambda and S3

This is more a general question about this project I have on. We need to implement some UI for our costumers to upload multiple files (2000+) every month, so we can send them by email to another ...
1
vote
2answers
127 views

PHP - Enforce classes to have method with parameter/return value of `self`

SCENARIO I am implementing "command pattern"-like classes. Since they are so similar to each other in so many sense (e.g. functionally, their relation in domain problem, etc.), it is desirable to ...
-3
votes
1answer
112 views

What kind of factory method abstract singleton design pattern is this?

I made a code that seems to mix Singleton design pattern, and Fatory method. But my factory method is in an abstract class inherited by my Singleton ... what the hell have I created ? Does it have a ...
2
votes
2answers
95 views

Elegant way to relate two php scripts

I have been writing some code in PHP for a bit of time, but I am still pretty new on it. I have a script with all functions I need for my webapp. The script looks like this? function foo(bar){...} ...
1
vote
1answer
103 views

What is the easiest and most flexible to scale method for handling recurring tasks that don't have an end date and will dynamically change?

Problem: I'm writing a service in Laravel 6.2 that will send out a push notification to different users at specified times down to the minute. Users select how many times a month, week, or day and at ...
0
votes
0answers
23 views

Import many data using dto between multiple modules

I am working on a symfony application where i have complex user data coming through an external json feed. This data is usually a 100MB json feed from which i have to read user data (with all its more ...
2
votes
3answers
80 views

PHP : authentication with a temporary link

in my system users register with their email address and receive a temporary link to log in. hostname/login/OYkwIJt6be1V5kMg10G The token must be generated from the email adress of user and valid ...
2
votes
4answers
209 views

Is it a bad practice to query remote resources inside validation?

Watching this talk about Symfony Forms and validation, at 23:06, I got stuck with a doubt I couldn't find a satisfying answer to: Is it a bad practice to execute a query (or a web request, or a side ...
1
vote
2answers
42 views

Create object(s) to cater for two data sets that are the same entity but one has an additional element

When I call an API endpoint I have a class to create an object with the response. The object directly maps the endpoint elements so I have all values, with properties, getters, and setters. In my ...
1
vote
2answers
204 views

Clean Architecture - How to pass request data towards inner, domain level Use Cases?

Use Case Interactor: We can see it in this picture how does a request cross the layers until it reaches the Use Case Interactor. How does the controller pass the request towards the Use Case ...
1
vote
2answers
50 views

Event Sourcing - Can a read model/projection be used in business rules within an aggregate?

I know that the general concept behind event sourcing is that the state of the application should be able to be replayed from the event stream. Sometimes, however, we need to get information for ...
0
votes
0answers
12 views

Using both jwt tokens & api lifetime tokes in Laravel app

Previously I had some experience using JWT tokens when making SPA. The workflow is: User enters email & password, gets JWT token, the token is stored in local storage and is passed in each ...
2
votes
2answers
88 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
1answer
38 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
34 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
86 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
26 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 ...
2
votes
0answers
39 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
118 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
55 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/...
1
vote
1answer
69 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
34 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
101 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 ...
1
vote
1answer
44 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
569 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
163 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
88 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
127 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
37 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
124 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
147 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
41 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
303 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. ...