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
54 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
76 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->...
14
votes
9answers
12k views

When do I need to use a framework? [closed]

I am new to web programming and at this time I am learning about PHP. I would like to know when do I need to use a PHP framework such as CakePHP? What are things that this and other similar PHP ...
0
votes
1answer
164 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 ...
2
votes
2answers
231 views

Child class accessing its parent's method from Ancestor method

I find myself right now banging my head with the following issue (in PHP): I have an abstract base class, which has a non-abstract method, inherited and unchanged all over the inheritance chain (...
-5
votes
1answer
113 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 ...
-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
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 ...
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 ...
0
votes
1answer
149 views

Question(s) about PHP PDO connections

Let's say I have a Db class [ db.php ] : <?php class Db { // class properties private $db_driver = ''; // dsn credentials private $db_dhost = ''; private $...
-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 ?
1
vote
1answer
135 views

How to compute Pricing of Product & Options based on User Option Selection and Pricing per Option

I am building a service for pricing options of a product and for pricing the product itself when product has various options. Example User selects some X options out of Y options available, where X &...
-4
votes
3answers
409 views

Why different languages have different syntax? [duplicate]

Different programming language always/most of the time use different syntax. For example take PHP, Java and Python. In Php & Java semicolons are compulsory at the end of the line, yet Python ...
0
votes
1answer
3k views

Reporting Solution in PHP / CodeIgniter - Server side logic vs client side

I'm building a report for an end user. They would like to see a list of all widgets... but then also like to see widgets with missing attributes, like missing names, or missing size. So i was ...
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 ...
-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 ...
7
votes
3answers
2k views

Help understanding server-side scripting

As far as I understand, there are basically 3 options for doing server-side scripting these days: Using scripting languages that can be directly interpreted/executed by the web server (e.g., PHP and ...
0
votes
1answer
161 views

How can I cancel all running MySQL queries in a web application?

I am running a web application which has to scan (MySQL query on a particular column) a huge MySQL table, which has over 100,000 records. The problem is that when a user requests another page from ...
-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
219 views

Explain ServiceLocator pattern of ZF2

I am looking at this example: http://framework.zend.com/manual/current/en/user-guide/database-and-models.html Relevant excerpt from above: class AlbumController { public function getAlbumTable()...
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 ...
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 ...
0
votes
3answers
558 views

How do I handle 3rd party search result data (via cache)

I have a search function on my site and it is taking data from 6 different 3rd party resources. The problem is, it takes too long requesting the data over and over again on the results page. I've ...
2
votes
1answer
129 views

Fine-grained data level permissions on a laravel RESTful API

The problem: We want to restrict access to properties returned from our services. Details: We have route level permissions working with no issue. For a user that can view /product/{id} for example,...
26
votes
5answers
9k views

should I throw exception from constructor?

I know I can throw exception from constructor in PHP but should I do it? For example, if a parameter's value is not as I expected it. Or should I defer throwing an exception till a method is invoked. ...
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 ...
-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 ...
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; ...
5
votes
1answer
295 views

Evaluating data set with a string formula in php

I was tasked to update some conditions in an application. I have a data set to be evaluated, and it has been hard-coded in the application following way: $arr = array( 'a' => 'apple', 'b' => '...
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, ...
4
votes
4answers
8k views

The best possible way to implement Business Rules in PHP

I'm planning to write an e-commerce app using PHP & MySQL with lots & lots of custom rules. Say for example, I want to have a rule like "Give Customer X, a 10% a discount for Product Y if he ...
0
votes
2answers
53 views

Kind of Servlet (J2EE) for PHP?

I'm coming from a J2EE development environment, and by there, I used a Servlet context to hold all the website meta data (title, description ...) for the whole application (some kind of a session for ...
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 ...
8
votes
1answer
205 views

Algorithm to generate Edges and Vertexes outwards from origin with max multiplicity of 3

I am creating a 2d game for a website where the universe can grow extremely large (basically infinitely large). Initially, the universe is composed of 6 stars that are an equal distance from the ...
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 ...
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. ...
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 ...
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 ...
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 ...
4
votes
2answers
619 views

Use a global variable, a singleton, or something else

Preface: I am working in PHP (Abandon hope all ye who enter here). Background: There exists a large set of global functions in PHP, a number of which are miscellaneous system calls, like sleep (and ...
2
votes
0answers
181 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 ...
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,...
3
votes
1answer
273 views

Building dedicated codepad in PHP

I am author of growing framework, which is focused around User Interface building in PHP. Essential requirements for the up-coming website redesign is ability to run code examples. I am willing to ...
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
69 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 ...
0
votes
1answer
279 views

Implementing SEO for a Zend Framework/PHP/Angular.js application

A team has implemented a web application using MySql, PHP with the Zend framework and Angular.js on the client side. I am in charge of implementing the SEO for this application. I understand I have ...