Questions about PHP, a widely-used general-purpose scripting language that is especially suited for Web development.

learn more… | top users | synonyms

0
votes
0answers
51 views

Pass the parser to the sorter, or pass the sorter to the parser?

I have 2 objects that I'm not very certain what is the proper (or better) way I should use. I have a query builder object that constructs an SQL statement like $qb = new SelectQuery('users'); $qb-&...
0
votes
1answer
74 views

Best way to encrypt passwords?

I've switched to PHP 7.0 very recently and I was wondering that if password_hash was better than making your own salt and using the crypt function. I have three examples of code and I don't know which ...
0
votes
1answer
47 views

designing php POST interface to mobile app

Currently I am working on php application, to create interface that will receive POST data from mobile app, and process them into shared database. To do things right at a first time, I was searching ...
2
votes
0answers
137 views

Is Nested Structure with Spread Responsibilities Not Logical?

Given the following code snippet in a Laravel Controller: $this->userRepository->saveByProject( $this->fileRepository->saveByProject( $this->metricRepository->...
0
votes
1answer
163 views

Script to protect code duplication [duplicate]

I want to sell my source code, it's written in PHP and CodeIgniter. And it's actually a CMS for personal website. My intention is to create only one license for one use only, if someone buy this code ...
-4
votes
1answer
83 views

username exists in two database table [closed]

how to check if username exists in two database table? First database table; $username = $user->username; $userexist = Approval::where('username', '=', $username)->get(); Second database table; $...
1
vote
1answer
101 views

How would you test this class and is it integration test or unit test?

Consider this example class which in encrypting some data and sending it to some other service. Consider the test for redirect method. This is how you consume the class: <?php $safeLink = new ...
1
vote
1answer
55 views

Recursive interface implementation causes empty method

TLDR: I have a situation where interface implementations accept other implementations of that very interface. Only a subselection of these interface implementations should carry a certain method - but ...
-4
votes
1answer
157 views

How does $a = 5; $a = $a + 1 ; equal 6? [closed]

Can someone explain this code : <?php $a = 5; $a = $a + 1; echo $a; ?> The output is 6, How? what did save in RAM? $a = 5 or $a = $a + 1 ?
-5
votes
1answer
112 views

Insert data into database without using form

Do i insert the current directory files name into the database in PHP but without using the form??.. Because in my project a device send the pdf files on server's folder and i want to save these files ...
-3
votes
0answers
51 views

Status update according to time set in database

I am new to php and phpmyadmin, I am currently working on a project to build a website for employees to update their in/out status. I have created webpages for admin to add users and let users to ...
-1
votes
2answers
92 views

Is using AJAX worth it in the inner administrative system?

Imagine we have a administrative system that is designed to be as fast and lean as possible, without too much fancy CSS or JS. The UE is not that great, but still it is pleasing on the eyes and gets ...
2
votes
1answer
73 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 programme (maybe with the use of a DI-container) and then inject the objects ...
-1
votes
0answers
64 views

Good examples of using “private” visibility in PHP [duplicate]

This is a pretty basic question, but I think a lot of people would benefit from the answer. When I'm coding in PHP I find myself almost never using "private" visibility on anything, I almost ...
0
votes
1answer
47 views

Use redundant data in database design when have multiple relation

In my web application users can submit their advertises and buy package for advertise (packages are used for priority of showing advertises) Database schema is like this: **Package: id, title, ...
1
vote
0answers
63 views

What would you call this design pattern? MVC or PAC

I have been reading and researching about MVC, HMVC, MVP, MVVM and PAC design patterns when I came accross this article by larry garfield > MVC vs. PAC My Implementation: Think of a modular app ...
1
vote
1answer
112 views

Functional Programming in PHP

Modern PHP is mostly written Object Oriented. Other than the fact that there is inertia towards the Object Oriented in the PHP community, is there anything about the language itself that would make it ...
6
votes
0answers
90 views

App opening standard browser instead of active browser

Say you have a smartphone with two browsers, DefaultBrowser and OtherBrowser. You visit the webshop by opening Otherbrowser, and proceed through the cart steps At the end, you go from OtherBrowser ...
5
votes
4answers
383 views

Is it good practice to use a single database connection?

The PHP codebase I'm working on has an utility class that returns a database connection. The implementation looks like this: class Database { private static $conn; private static $init = false; ...
2
votes
1answer
144 views

Can I add to a built-in function?

I want be to be able to re-write the code of an existing PHP function in an abstract manner. Here is an example: scandir() scans a directory for files and folders, and returns the relative paths '.' ...
1
vote
0answers
55 views

Dynamic Printing Options

I believe this is the correct community to post this question in, if not please point me to the correct one. Overview: Current web app gives users the ability to print labels from specific printers. ...
1
vote
3answers
81 views

Return values for a delete function in php

I am writing a wrapper function for database calls, and I am confused about the best way to handle the error cases. The function has only one argument, the id of the object to be deleted. I've ...
0
votes
1answer
66 views

Manipulating DOM via script or rebuild website - which is better?

Let's assume you want to change what user sees on the website. There are two ways to do that: a) manipulate the DOM via JavaScript, but user has to download whole script, with possibility he may not ...
0
votes
1answer
109 views

How to search through an array of objects?

I am using an array of objects to store data to render a page. A few examples of the type of data each object can contain: PHP filepath for an include CSS filepath for CSS files Meta data of the ...
3
votes
0answers
55 views

Where should view-specific data/logic be defined in a PHP MVC application?

After many hours of research and thinking I have found an understanding, then coming to question it again, I am struggling to find something concrete which I can grasp and apply to my code in a ...
2
votes
2answers
176 views

where to put which code in MVC model

I recently picked up learning PHP and MySQL and I am trying to build a small usersystem as a coding exercise. While learning to use classes and functions, I also stumbled upon the MVC model and would ...
2
votes
2answers
98 views

Can a single Factory be used to create similar in purpose, but different in focus objects?

I am concerned about whether or not I am using FactoryMethod correctly. Background: I am refactoring legacy code and I have identified a pattern: there is a God Object that is created in memory,...
0
votes
4answers
499 views

Do i have to make all my website PHP with embedded HTML to make a good secure website?

I see all websites (THE big ones) make both PHP and HTML in same page .. Do I need to make all my website pages as PHP and embedded HTML inside it ? Can't I make the website all as HTML Pages and PHP ...
1
vote
1answer
116 views

Php-mysql injection

<?php error_reporting(E_ALL); //ini_set('display_errors', 1); $db_server = "localhost"; $db_name = "2"; $db_user = "root"; $db_passwd = ""; $connection = mysql_connect($db_server,$db_user,$...
0
votes
2answers
68 views

Reading the result of your command with the Command Pattern

I am currently looking into developing a new system utilizing hexagonal architecture and the commandpattern facilitated by a commandbus like tactician (it's a PHP system). Now I really like the idea ...
2
votes
0answers
81 views

Are there downsides to writing PDO/mysqli statements into my code directly vs using my own redirect wrapper methods?

TL;DR: To access DB functionality in my codebase I currently use a custom layer throughout the code. The layer needs an upgrade in order to begin accepting prepared statements, which it currently ...
0
votes
1answer
79 views

How to display recent post on website and make own search engine ? With PHP

On OLX like Website , Anytime a user posts a new ad. It comes in top of the page. No search is involved in it. Which technology we can use to make such functions. Suppose X is visiting my website ...
1
vote
1answer
64 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
52 views

How should i handle deeply nested data with codeigniter/mvc?

I want to build a website with categories, pages, sections and slides. Hierarchically it should look something like this: [category 1] [page 1] [section 1] [slide 1] ...
0
votes
2answers
223 views

A few questions about model objects in a MVC

I have a few questions about how to implement models and what the results are of those implementations: When I only need a few variables set, isn't it memory consuming to create an entire object? E....
0
votes
1answer
67 views

Laravel Eloquent - Filtering results and eager loaded results

So here is the use case: You have users and they have many addresses. Say you want to filter and eager load on addresses (say...only US addresses). In order to do so you have to filter the eager load ...
1
vote
3answers
174 views

How to gently steer a giant PHP app toward better practices? [duplicate]

So I'm responsible for maintaining and enhancing a PHP codebase that runs to around 1,100 files and 120,000 lines of code. In general, it's not terrible, although since it was written over some 10+ ...
-1
votes
2answers
170 views

The best way to create a PHP chat system

I'm into creating a php based web chatting system. About 1000 concurrent users across the world will be using it, so what would be the best tech to deploy? As I did some research online, mainly I ...
0
votes
1answer
52 views

Creating a facet filtering using Elasticsearch

I have been asked to create a filtering functionality for e-commerce application written in PHP. Since the app is using MySQL database, I made the decision to use Elasticsearch with Logstash and ...
1
vote
1answer
45 views

PHP primitive types: are objects primitive types?

I am reading through PHP Objects, Patterns and Practice 4th Ed and on page 41, Constant Properties chapter says: Constant properties can contain only primitive values. You cannot assign an object ...
-4
votes
1answer
60 views

PHP access external website like human access

I would like to code and API, the API would access an external webpage like human, the external site needs user, pass and verification code/capcha. PHP application will access that page by providing ...
2
votes
0answers
180 views

Symfony2 - Best aproach for a plugin system

Symfony2 is handling all its things in bundles in /app or in /vendor. This is fine, if you are handling and managing all by yourself or Ops that handle all needed things. But I haven't found a good ...
0
votes
1answer
61 views

Conditional factory

I need to perform a payment and I have two payment methods: FirstPayment and TokenPayment, which both implement PaymentInterface interface PaymentInterface { public function pay(PaymentRequest $...
1
vote
2answers
112 views

Planning to convert PDF to JPG, Annotate the image, Reconvert to PDF

I have a feature where scanned exam answer books need to be digitally annotated and marked. The scanning portion of the work is with another vendor who refuses to scan in any format other than PDF as ...
1
vote
1answer
60 views

Why does ORM persist() functionality use references to populate insert_id and not return?

My understanding of how ORM persist works: //ORM "persist" oversimplification function persist(&$entity) { ... $insertId = api_actual_db_insert(...); $entity->setId($insertId); } /...
1
vote
1answer
173 views

Laravel 5.2 - Better to create a Service Provider or Helper class or otherwise?

So I have created an API endpoint (obviously not restful) that generates xml and returns the file path of the files. Its obviously more complicated but that is the gist. My issues is this. Inside my ...
0
votes
1answer
115 views

Using numeric arrays or associative arrays search and retrieve data ? [ file paths of a page]

I am building on a CMS where dependencies and files needed for a page get stored in the database. Because this can be very dynamic, I serialize these paths into one Database field into my pages table. ...
0
votes
0answers
34 views

Resolve route before invoking middleware chain

Say I have a HTTP middleware chain that handles all incoming requests. Where should the incoming request be resolved into an appropriate route? I have thought about doing so before the middleware is ...
13
votes
2answers
1k views

How to go about testing un-injectable code?

So I have the following piece of code in use all over my system. We're currently writing unit tests retrospectively (better late than never was my argument), but I don't see how this would be testable?...
3
votes
1answer
119 views

Is there a good way to use the front controller pattern for command line applications?

I am a PHP developer and I used to build web applications with one PHP file per page for a very long time. This resulted in duplicated logic and messy code (even though I didn't know it at the time). ...