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

learn more… | top users | synonyms

3
votes
1answer
128 views

Can this be considered an API? [closed]

I'm writing my first API, but I think I screwed it up from the design. It's a simple CRUD API which behave like this: READ: /api/data gets redirected to api.php?data1=data. POST variables: user, ...
1
vote
1answer
216 views

How harmful is using switch(true) as a way to handle multiple conditional statements? [duplicate]

I recently saw something like the following: switch(true) { case iAmAmazing(): { return 'some html'; } case isVariable: { return 'some other html'; } case ...
-1
votes
0answers
31 views

oauth2, grant types, and mobile apps [closed]

I'm implementing a webservice which utilises oauth2 Specifically using this library: http://bshaffer.github.io/oauth2-server-php-docs/ I have the beginnings of an android app that will access the ...
-1
votes
1answer
226 views

Is it always better to use __construct() in CodeIgniter's Models and Views, even if it's not needed? [closed]

Sometimes we have Models and Controllers where the function __construct() just doesn't do anything, but is sitting on the top of all the methods in CodeIgniter's models and controllers. A lot of ...
5
votes
1answer
271 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' => '...
5
votes
3answers
407 views

Comparing two large strings to see how much they match [duplicate]

Is there an easy way of comparing any two different size of string text to see how much percentage they're alike? I'm trying this but I'm running into to this issue below. The left text area is the ...
0
votes
1answer
136 views

Webdesign MVC - going in the right direction?

I am trying to learn webdesign using the MVC design pattern. Right now, I am stuck at a point where my code gets more complex, and I am unsure about the structure and where to put which code parts. I ...
3
votes
3answers
122 views

Which pattern can I use for doing computations involving similar yet different object subtypes?

How do I design code that has two qualities: uses similar but different subtypes of an object uses similar but different types of computation on the above objects Example I am refactoring this ...
0
votes
0answers
162 views

How does postback url works in campaign tracking systems?

my question is theoretical, a vague idea or some sort of algorithm will be great. I am building an advertising campaign tracker web app for a friend, yet i am kinda lost, i cant figure out how the ...
0
votes
1answer
56 views

Compute geographic areas Laravel

I am developing a backend for a taxi app in Laravel 5. Up to now, served areas are defined by the admins but I would like to change the way it works. I would like each taxi driver to define their ...
0
votes
1answer
88 views

Laravel 5.1 creating model overrides per client

Okay, so I have a Laravel 5.1 project with close to 200 models. This is fine for the core operation of the app, however, in many cases a client may want us to grab something from the database in a ...
1
vote
2answers
194 views

Declarative parser for JSON and DOM

I am parsing many JSONs and DOMs in PHP. The problem is that the my knowledge about the structure of the JSON/DOM is mixed with code. For example, suppose that I have few sources of first and last ...
0
votes
1answer
295 views

Laravel Algorithm for taxi app

I am trying to write a backend for a taxi service (university assignment) and I am stuck on the algorithm. whenever a new client posts a request, all the taxi drivers nearby get an email notification ...
2
votes
1answer
89 views

API and a shared API client

We are a startup kind of a project that fired pretty well and as all startups the main goal was to start ASAP. We made our project as a monolith application (PHP) that has 4 sub-applications, but will ...
0
votes
2answers
397 views

Shopping cart in PHP : Sessions or Database? [closed]

I am currently developing a simple shopping cart using PHP & HTML. I've been having troubles with using the SESSIONS in Php like: Sessions not continuing when I switch pages even though I ...
5
votes
3answers
419 views

Composition over inheritance but

I'm trying to teach myself software engineering and coming up against some conflicting information which is confusing me. I've been learning OOP and what abstract classes / Interfaces are and how to ...
1
vote
4answers
111 views

How to design class model for specific products, some of which may contain groups of specific product models

Class Design Question I am trying to figure out a good way to design my class system. I have a class Product to compute various product specifications. I have two product model groups, each ...
2
votes
1answer
113 views

“Vendor” name changes when the vendor name changes

PHP (PSR-2, anyway) recommends using the vendor name as the root namespace for projects. At face value, this seems to mean we should use the current name of our company. But I work for an enterprise ...
0
votes
0answers
50 views

how to create messaging storage structure in redis?

I am developing Node.js, Redis based chat application in php. I had an idea about chat logger structure but I required suggestions that how and what to choose proper data structure to create Redis ...
1
vote
1answer
151 views

How often should I use try/catch statements? [duplicate]

Everything I've read says that they should be used when something that simply "shouldn't happen" does happen. But the thing is, there's a lot of things that could go wrong. For example, if I'm ...
2
votes
2answers
89 views

Advantages of extending the default Exception class

I've seen that it's possible to extend the default Exception class in PHP, enabling one to throw an IncorrectParameterTypeException exception, or a ValueOutOfRangeException exception (maybe these are ...
-1
votes
4answers
455 views

Fundamental issues of programming [closed]

I just let my brain run wild and the results are again chaotic. It is kind of bothering me how in the very basics, programming itself can be pretty redundant. Let's look at this snippet of code and ...
0
votes
0answers
58 views

How to handle 301 redirection loops?

I'm working on custom 301 redirect module. I am getting a redirection loop if source url == www.xyz.com/aboutus/*.php and destination url == www.xyz.com/aboutus/xyz.php or source url = /abc/* and ...
1
vote
4answers
260 views

How to deal with long running transactions?

I'm developing a Content Management System (CMS) and I would like to include a "Save Changes" button. I mean: a user performs several changes in the database, but those changes are still not available....
0
votes
1answer
129 views

Child classes only change some “options” - what's the best approach?

I'm currently implementing functionality in Symfony (PHP - not that it should make any difference which language I'm using) where I have about four controllers that do almost exactly the same thing. ...
0
votes
0answers
36 views

MVC single view file with multiple uses depending on passed in value

I'm using Laravel with Blade to build a simple maintenance application for my work. One of the functions of the application is to display simple statistics for a piece of machinery. To keep things ...
-1
votes
4answers
446 views

Why do negative numbers evaluate to true in PHP? [closed]

function haha($lol) { if($lol) { echo "plus"; } else { echo "minus"; } } haha(-1) echoes plus. Is it because PHP uses twos complement? Google search wasn't really helpful.
3
votes
2answers
106 views

Best way to develop new features as well as fix any bugs for a web system on Windows [closed]

I'm a one-man band and I have a contract with a client to develop and maintain a web-based system that is relied upon. This is the first project of this size and type that I have done for anyone else ...
-1
votes
1answer
168 views

Understaing the “fillable” in Laravel migration [closed]

Using models is one the best facts in Laravel, but when using a model, it is not like my "native" environment (J2EE, models declare all DB table colums), it has three variable, and which of them is "...
0
votes
0answers
32 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 ...
0
votes
1answer
93 views

How to split a class that is an implementation of interface?

Let's say there is class called AccountingService. Using this class I fetch all kinds of ecommerce records like products, customers, etc. The fetching happens inside a controller action. Once fetched, ...
0
votes
1answer
1k views

Folder structure for app with Symfony 2, React, Webpack, and Sass? [closed]

I am creating an app that uses some components of Symfony2 along with React, Webpack and Sass. We will mostly code in PHP, with the other things adding functionality to our app. I'm having a hard time ...
0
votes
2answers
148 views

Incrementing Strings in PHP (and Perl)

PHP allows you to increment strings. Why? Let's jump ahead a bit. Take the following code: $string = '9ZzZ'; echo ++$string; // 10AaA From a purist point of view this may seem like nonsense, ...
0
votes
1answer
131 views

Can I execute a query in a catch block of try-catch? [duplicate]

I want to confirm the right approach of using try-catch exception handler. I have written a query in a try block, and if any exception is thrown, it will execute a query in a catch block. Is this ...
0
votes
2answers
112 views

REST Service Description in a Hypermedia agnostic way?

How do I implement REST service description in a Content-type agnostic way? Background I am developing a RESTful API for Web Application. Now this app is somewhat different than a standard run-of-...
0
votes
1answer
194 views

Efficient way to store large number of image path per record into a database table? [closed]

I am trying to think of an efficient way to achieve this. We get a zip file that has a XML file containing around 1500-2000 items. Each of the item could have up to 20 images for it. The images are ...
4
votes
3answers
368 views

Name of this pattern to wrap functionality

I have a system that allows certain functionality to be implemented different ways, but requires that the functionality of each implementing class be wrapped in another layer. For example, each ...
0
votes
0answers
84 views

Broadcasting events asynchronously in a high frequency application to prevent hangs?

I'm doing a bit of socket.io work in an application that demands high frequency updates with minimal wait times (imagine a commentator annotating a video livestream, with viewers both watching the ...
1
vote
1answer
417 views

Array vs Object for View in Laravel

First, yes This question is very similar to Arrays vs Objects in view template but my question sort of expands on this... When deciding on whether to use an object or array to pass data to your view. ...
0
votes
2answers
139 views

What is a readable algorithm for selecting a random buyer based on what they purchased?

I am working on a giveaway algorithm to select a customer based on what they purchased: If they purchase item 1, they gain 1 point. If they purchase item 2, they gain 2 points. If they purchase item ...
2
votes
1answer
198 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
280 views

Tracking hours with clock in/out

I am working on a web interface that would allow the user to keep track of the amount of time people spend at their establishment. The problem: I don't know what the best way to keep track of this ...
3
votes
2answers
354 views

Roles and permissions: a good approach in defining permissions?

My application has users and administrators. The administrators split into two: super-admin and limited-admin. The super gets all permissions while the limited can be configured to inherit just the ...
1
vote
1answer
218 views

PHPDoc Comment, Class vs File

I am trying to standardise my code as much as possible, including DocComments, using PHPCS. It seems that the PEAR standards contain two sniffs that require almost exactly the same tags appear in the ...
0
votes
1answer
128 views

Best pattern to write a PHP function that checks on access and returns more then boolean?

I'm prototyping behaviour of a new application, and want to write some functions that check on access based on some variable dates. I just want to write separate functions for that, like "...
0
votes
1answer
164 views

Coding to an interface vs more generic interfaces

I have a number of classes (and interfaces) which 'code to an interface' interface File { ... } interface FileConverter { public function convert(File $file); //coding to an interface ...
2
votes
1answer
81 views

Reusing an interface or method chaining

I am learning about coding to an interface in OOP programming. I understand you should code to an interface so you can 'swap out' functionality. However, I have a situation where I feel I can reuse ...
1
vote
0answers
114 views

Are facilities that generate HTML for you, considered harmful? [closed]

I will approach this from two directions (+ raw HTML itself being de-facto third) Proprietary HTML-generating code Code generating facilities provided by a popular library Proprietary HTML-...
1
vote
1answer
226 views

Synchronize database with external API

I currently own a website where players can look-up their statistics of a game. When someone that is not in my database yet requests their statistics, I am calling the API with a PHP cURL request and ...
1
vote
0answers
58 views

Storing reference to a model obtained using DataMapper to be able to call save on it

When using the DataMapper pattern, which involves modeling classes containing business logic and knowing absolutely nothing about persistence, caching,... I usually want the models to represent real-...