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
28 views

Design Pattern where Backend and Frontend Code are in One File [on hold]

Forgive me if this is a simple question but I have not been able to find the answer for this anywhere online. What is the name of the design pattern in web development where both front end and backend ...
1
vote
1answer
245 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
3answers
105 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 ...
7
votes
1answer
509 views

General approach to re-factoring a large, very badly written legacy system [duplicate]

Possible Duplicate: Techniques to re-factor garbage and maintain sanity? What is a good way to refactor a large, terribly written code base by myself? Really open question here. I'm not after ...
1
vote
2answers
67 views

Considerations for delegating long running to CLI from PHP/Apache

I'm working on a web project that executes CLI commands to perform running tasks to spare users from having to wait since PHP/Apache combo cannot (to my understanding) create a separate process for ...
1
vote
1answer
63 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
1answer
101 views

Database abstraction layer

I'm currently developing an SaaS application in PHP, with Laravel, using its own DB class. Let's pretend we've got 2 classes under 2 namespaces, plus Laravel's own DB - so Illuminate\Support\Facades\...
0
votes
0answers
9 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 ...
0
votes
1answer
28 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
6answers
110 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 ...
1
vote
1answer
87 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 ...
1
vote
0answers
34 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 ...
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
65 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 ...
2
votes
4answers
411 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
1answer
29 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
76 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
20 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 ...
0
votes
0answers
37 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
120 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
34 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 |...
14
votes
5answers
37k views

How to structure template system using plain PHP?

I was reading this question over on stackoverflow: https://stackoverflow.com/questions/104516/calling-php-functions-within-heredoc-strings and the accepted answer says to do plain PHP templates like ...
1
vote
2answers
79 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
131 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
2answers
87 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 ...
10
votes
3answers
8k views

How to consume external RESTful API with Symfony?

We are building a Microservice architecture for our projects, with mostly front-end Symfony applications interacting with back-end RESTful APIs. The problem is this approach is breaking the Symfony ...
0
votes
3answers
197 views

Do i need 2 tables to book entity?

I am developing a website to store books info such (title, book_no, author, edition, container...). I have two types of insert insert series of books (Eg: harry porter series: chapter 1, 2,3...) ...
0
votes
1answer
69 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 ...
28
votes
7answers
70k views

Which is better: to include HTML inside PHP code or outside it?

Look at this: <?php echo "Hello World"; ?> <br /> <?php echo "Welcome"; ?> And now look at this: <?php echo "Hello World"; echo "<br />"; echo "Welcome"; ?> Which one ...
0
votes
1answer
36 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 ...
-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 ...
4
votes
2answers
825 views

How to think in Object Oriented way when it comes to passing messages?

Somewhere I have read that "Object Oriented" is a misnomer and that OO should really stand for "message-oriented programming". What I am not clear about is ... what does it mean? For example in ...
5
votes
2answers
16k views

Can python and php work together?

I am having a mobile app created for ios. The developers built the app in php. The app requires an algorithm so I found another programmer to develop it. The algorithm programmer built the algorithm ...
4
votes
2answers
769 views

PHP OOP dependency injection - when is it o.k. to use the “new” statement

I was told to avoid "new" statements in classes or functions but rather create the objects from classes in the root of the program (maybe with the use of a DI-container) and then inject the objects ...
2
votes
1answer
790 views

Relations between entities in DDD

I am a beginner on DDD, working around small, simple domains in order to get my head on all the principles of design. I have this simple domain: institutions (Institution) and their available WiFi ...
11
votes
2answers
7k views

Why PHP treats “0” as FALSE in boolean contexts?

"0", as a string containing one character, is not something empty intuitively. Why does PHP treat it as FALSE when converted to a boolean, unlike other programming languages?
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 ...
10
votes
2answers
3k views

Exceptions in DDD

I'm learning DDD and I'm thinking about throwing exceptions in certain situations. I understand that an object can not enter to a bad state so here the exceptions are fine, but in many examples ...
0
votes
1answer
75 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 ...
6
votes
2answers
2k views

Repository pattern implementation that knows nothing about the database table and column names

I've seen around the Internet and Github, implementations for the design pattern Repository that knows about database table and column names. I was think, if I want to work with the database as a ...
184
votes
8answers
165k views

Is it bad practice to use <?= tag in PHP?

I've come across this PHP tag <?= ?> recently and I am reluctant to use it, but it itches so hard that I wanted to have your take on it. I know it is bad practice to use short tags <? ?> ...
6
votes
2answers
5k views

What is the difference between PHP and ASP.NET Web Forms in page size?

I plan to program web applications for small companies. When I read about ASP.NET Web Forms, I liked its way of building dynamic sites. However, I have heard from a friend that Web Forms could ...
7
votes
1answer
349 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 ...
0
votes
0answers
54 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 ...
2
votes
1answer
177 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
52 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 ...
10
votes
3answers
2k views

What's special in July 26th and why is it used in examples for Expires header so often?

I've noticed that July 26th (my birthday) is used really often in various PHP examples related to preventing http caching using Expires header, like: https://stackoverflow.com/questions/12398714/...
0
votes
1answer
139 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 ...