Questions tagged [php]
Questions about PHP, a widely-used general-purpose scripting language that is especially suited for Web development.
2,040
questions
0
votes
1
answer
139
views
How to handle complete rewrite of a file in regards to code review
My situation is this: I am contributing to a Symfony/PHP project. I had to completely reskin one page in the application. The controller logic is almost totally unchanged. I only had to change the ...
0
votes
2
answers
2k
views
Where should permissions be stored in a micro services architecture
We are currently in the process of building a service (a REST API) which is called on by our primary application. The primary application contains a users/permissions/roles set up which is used to ...
1
vote
1
answer
132
views
How can I make sure my PHP code is compatible with a newer version
I have a bunch of PHP 5.6 code that I would like to get up to 7.2. My biggest concern was the change that causes an error when you call a function without enough parameters. Previously, this was a ...
2
votes
1
answer
40
views
How to collaberate UI Team & Development Team for smooth development process over time to adapt changes in design?
The UI team deliver the HTML files to the development team.
Developers code PHP on html files to make the website.
But later we face a lot of changes in design. The designing team makes the changes in ...
0
votes
1
answer
493
views
Unit tests involving library functions and objects
I am making a project using the Laravel framework.
I plan to create unit tests for my project. But I feel I don't really have an idea what to test because I mostly use library or framework functions. ...
6
votes
1
answer
2k
views
Why place Composer in separate docker container?
Note: this question is not strictly PHP-oriented, since both Docker and Composer can be easily used outside of the PHP ecosystem (although such cases would be rather rare IMO).
In one of the projects ...
0
votes
1
answer
479
views
Should the function that operates on the object return it?
Should the function that operates on the object return it?
Shortened example:
class Example1
{
public function method($a, $b)
{
$result = new Result($a, $b);
$this->...
0
votes
1
answer
47
views
Some Questions on PHP execution?
I am new to PHP . I have primarily worked on java. I want to run the helloworld program for PHP. I got it how to do it through
blog
But I have got some basic questions :-
Do I need to install both ...
1
vote
1
answer
968
views
How to get email from Gmail to a PHP app
I'm building a PHP app which should somehow receive emails that are to be imported into user records. None of the solutions I've come up with will work (listed and explained below). I'm hoping ...
7
votes
4
answers
830
views
How are account balances persisted
I am currently building a finance application that contains "accounts"
Each account has a balance that is dynamically generated based on platform charges vs payments. e.g simplified example.
$...
-2
votes
1
answer
73
views
Web Security (PHP) - Is it Secure to do downloading files & presenting with Headers to the End User ?
I have security question that i am not sure if this approach is safe and secure way to download a file and present to a web user ?
We have customers invoice files stored in a server location (...
1
vote
1
answer
1k
views
How to white label my website in php
I have a website that follows the following structure:
www.example.com/city1
www.example.com/city2
...
Programmatically we change the logo which is hard-coded in a specific config file for city 1, ...
0
votes
1
answer
659
views
Is this a 'proper' use of a trait in PHP?
In Laravel 5.6 an Illuminate\Database\Eloquent\Relations\BelongsTo relation was given the ability to support default models. This allows a model that will be returned if the relationship is empty.
...
0
votes
1
answer
154
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 ...
2
votes
1
answer
2k
views
Java and PHP compiled vs Interpreted and runtime environment?
I have primarily worked on java. Now Learning PHP.
After reading couple of articles on google, i got the understanding but got some doubts too.
Compiled vs Interpreted
Java Compiled language :-
...
0
votes
2
answers
255
views
What makes PHP a language and jQuery a library?
PHP is written in C, but is considered a language. What makes it different from something like jQuery which is considered to be a library of Javascript? Why is PHP not a library of C or jQuery a ...
2
votes
1
answer
1k
views
How can I turn my CRUD database application into a REST application?
I may have gotten myself confused, when reading CRUD vs REST and how they are similar, so I wanted to explicitly ask: can I turn my CRUD application into a REST application, when I have a specific ...
2
votes
0
answers
98
views
Coupling form fields to functionality: using a Command Bus?
I built an app where the app owner can build custom forms for each of his clients. The forms have default fields like "name" and "message" as well as custom fields for each client requirement, like "...
1
vote
0
answers
814
views
Handling complex dynamic queries in Laravel 5
I am developing a project using Laravel. My workflow is:
route directs to controller
Controller calls eloquent models
Eloquent models perform queries (tipically CRUD and find)
Controller returns ...
0
votes
3
answers
395
views
PHP How can I get rid of redundant if statements
I have a bunch of if statements written in PHP for a project I'm working on. The pattern is that when the $price increases by 5 cents every time magazines are increased by 10. When the amount of ...
-2
votes
1
answer
61
views
Using a class as an attribute in another class or just one value?
I have a PHP script which has a group class and a component class. Each group consists of several components. My group has attributes groupName, groupId and componentList. My component has a ...
0
votes
1
answer
103
views
Is Dependency Injection A Standard in PHP and Laravel?
Or in actuality, how to tell if a certain technique has became a standard in certain language / framework?
As I understood from my readings so far, PHP supports DI in PSR-11 while Laravel uses it out ...
-1
votes
1
answer
41
views
How to find the best match (set of options) among several sets of options?
Imagine a couple dozen services (sets of options), each of which contains a subset of all available options. I want to create a web form listing all possible options so that users can check the boxes ...
0
votes
2
answers
263
views
Handling logging when there is no internet access
I'm developing an application that handles sales for multiple clients, when the client sells a particular item, that information should be send to the admin. The count of each item sold and the item ...
1
vote
2
answers
4k
views
Require_once in class files
I have a big system of classes and objects which rely on each other in order to function. Should I put all of the require_once() calls for dependencies at the top of each class file? ie:
<?php
...
2
votes
1
answer
239
views
Performance: Creating duplicate file
I have a Web server (Local) and File server(Remote).
I need to create a duplicate of an xml file in the same location with different file name in the File server. The size of the file is random, but ...
2
votes
0
answers
322
views
What Design Pattern to use to render PDF pages for a PDF Proposal?
I want to create a set of patterns to use for rendering a PDF Proposal (a set of PDF pages). I have made a good start, but not clear on how to proceed when more complexity is involved.
I am using ...
1
vote
1
answer
101
views
Should this part of my web-app implemented on server-side or client-side?
I want to write an application which monitors a few URLs (like a couple hundred) of all branches of school. By monitoring, we mean that it sends requests to those URLs at regular intervals (Interval ...
1
vote
1
answer
5k
views
Architecture / Design Pattern for Login Signup
I have a multi-seller ecommerce platform, derived out of Opencart 2.3. We changed quite a bit of the core code of the Opencart to add our own customizations, including features such as Seller ...
0
votes
3
answers
161
views
How do I deal with file downloads?
I'm currently working on a script (in PHP, but I'm not sure if that's relevant here) which allows users to set up a simple file-sharing system on their server. I'm stuck when trying to figure out how ...
2
votes
1
answer
82
views
How do I refactor a graph service to where I can encapsulate if/then/else statements?
I have a graph service where I use if/then/else statements.
class GraphService
{
function getGraphData(array $products)
{
foreach ($products as $products)
{
$...
2
votes
1
answer
2k
views
Entities and polymorphic relationships
Lets say that I have a shelf on which I can put items that are shelfable (not sure if that is actually a word but you can understand my point).
So I have the following:
class Shelf
{
/** @var ...
0
votes
1
answer
46
views
Is it appropriate to have a template get "streamed" data while rendering?
I'm dealing with code that renders HTML pages. I'm cleaning up an old, messy PHP code base.
Let's say I have a template that loops through a long list of rows in a database. I can load my data into ...
1
vote
1
answer
348
views
MVC: How to use data model list in recursive views
I am trying to learn web app MVC in PHP.Most of the articles discussed about 1-to-1 MVC pattern given bellow
Controller: gets user request & update model,
Model: receives orders form Controller &...
0
votes
1
answer
2k
views
PHP MVC controllers using ajax
I'm learning to use the MVC pattern to design my PHP's software. I always use ajax to send requests to my controllers so often I've a code structure like this:
<?php
if(isset($_POST['action']) &...
0
votes
2
answers
2k
views
Should i use an abstract class or an interface for my doctrine model?
In Doctrine, assuming I want to implement different types of vehicles. Maybe a car, a plane, a bicycle and so on ... all these vehicles have many different properties but also very common things like ...
0
votes
1
answer
90
views
Should I print to the page from a javascript object, or only render from PHP?
I have a complex app on the Javascript/PHP/SQL stack which manages different domain objects. The Javascript layer contains classes which manage the data on the client side.
I am currently baking a ...
3
votes
1
answer
258
views
if null is bad how we justify the "rfc" nullable for php language?
I do not understand how you think about it:https://wiki.php.net/rfc/nullable_types
when It is widely confirmed, that using nulls is bad practice
Where am I wrong?
thanks.
I'm not criticizing !.
I ...
3
votes
1
answer
134
views
Array rotation algorithm
I'm developing an application which sends quotes to clients via email.
Since quotes are obtained from various resources (per each client) they end up in a single array which is then used as a source ...
3
votes
2
answers
132
views
Where do I encode value conversion methods in an MVC web app to display values in different unit systems in the View?
I have a use case where I do internal data computations using English system, due to various precomputed graph coefficients and other data already using the English system. But for output I need to ...
1
vote
3
answers
3k
views
Setter with one parameter and null default value
Which solution is most logical? The value can be null, but when not null it must be a string.
This (First):
function setValue(string $value = null);
To me this is bad; since we can now call the ...
-2
votes
1
answer
8k
views
How can I do to use Angular 5/6 for frontend and Codeigniter 3 for backend in the same web app?
I have this project I want to do, using Angular 5/6 for frontend and Codeigniter 3 for backend. The problem is that I don't know how to combine the two, and all the tutorials I looked were using ...
0
votes
1
answer
225
views
Structuring Code to handle Authentication
I'm developing code which will be responsible for creating new users and modifying existing ones via an API in a user management system.
I have the authentication class developed, which handles ...
0
votes
2
answers
152
views
am i asking for trouble? DB & dealing with variable item records
I feel this is so basic, but it just seems too easy and obvious and why didn't someone suggest this 10 years ago. And I know there a lot of much brighter people than me in the software dev business......
0
votes
3
answers
206
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
1
answer
973
views
Dependency Injection in one method to other method params
A teammate of mine wrote some code in the following way:
Class Foo implements Job {
// Framework uses type-hinting for dependency injection, only works on the handle() method
// not on other methods
...
-1
votes
1
answer
464
views
Should the aggregate root have a property that it cannot validate [duplicate]
I ran into the situation where I have to decide whether a property belongs to my aggregate or not. My domain logic is the following. A User has a group in his organization ex: IT, SALES, MARKETING. ...
0
votes
1
answer
228
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
votes
1
answer
706
views
Refactoring bad code switch statment without distort everything
Once in a while I’m stumbling on switch statements during a
Code Review session.
I would like to find a more elegant way of this code
....
$istannceOfClass = $repository->loadFoo();
switch($...
-2
votes
2
answers
225
views
How much damage can a rogue PHP developer do?
It's often convenient to hire a remote contractor for front-end development. Frameworks, like Laravel, use PHP to render front-end so it would make sense to give the front-end developer rights to edit ...