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

learn more… | top users | synonyms

1
vote
2answers
137 views

Safety of magic setters in PHP

I don't know how in else languages, but in PHP seems to me that they are very unsafe way how to set value of any member variable - because one setter cannot easily validate input for many variables (...
3
votes
1answer
99 views

PHP OOP, structuring my objects properly

I have an architecture similar to this: User (Name, Email, ID...) ---- Studios (Name, Location, Description...) ---------- Videos (Title, Description, URL, Length, Views...) Simply put, a user can ...
1
vote
1answer
90 views

auto generated web CMS for pre-existing SQL db?

What I'm looking for is a way to auto-generate a simple web-based CMS for a simple pre-existing SQL database. To be used by 'app administrators', not the general public. Something that: allows ...
1
vote
1answer
128 views

How far do I separate Model code from Controller code when writing MVC?

I have some code where Controller depends on the Model, and in my case Model acts like a Database Access Object. use FQDN\Model; class Controller { /** @var FQDN\Model */ private $model; ...
2
votes
0answers
45 views

How to architect rule matching with multiple conditionals and outcomes

I'm working on allowing my users to create their own ruleset for data that's coming in. All of the data below is sample mock data and not in relation to our product. Example of a rule (there can be ...
7
votes
2answers
185 views

Am I using Zend Form library correctly? (I am effectively duplicating work in Controller and in View)

Brief Summary This question is asking for guidance on how to deal with Zend Form library that allows me to specify how to construct each form element (Controller side) and how to render each element (...
2
votes
1answer
131 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,...
1
vote
0answers
162 views

How to persist a session cookie in a PSR7 request/response middleware?

I am building a package that implements native-like sessions in a PSR7 middleware architecture. I created a middleware which is responsible to create and persist a session cookie. The session is also ...
1
vote
2answers
323 views

How to sync the data from the same user across multiple devices

I'm working on a small fitness app in which the user (whom is authenticated with the a server) could create their own workout plan which will be synced with a server. The problem with this is that ...
3
votes
3answers
274 views

Modern recommendations for password recovery

I'm going to implements password recovery in my authentication. I haven't put this together in a while and wondering if there is anything I ought to be aware of. My idea at the moment is: User ...
1
vote
0answers
121 views

Data Mapper pattern vs. model encapsulation

I am currently developing my first custom data mapper layer but have run into a conceptual problem that seems to be glossed over all books and guides I have read. My problem is as follows. My data ...
0
votes
1answer
122 views

Is there ever a reason to use variable variables in PHP rather than an array? [closed]

Is there any situation where an array is not suitable but a variable variable is? I cannot think of one or find one on any Stack Programmer Q&A. <?php $foo = array(); for($i = 0;$i < 3; $i+...
1
vote
1answer
151 views

Make PHP sessions truly last until the browser closes, and regenerating session on page requests

We have an issue where sessions are ending after a short time, 1440 seconds according to gc_maxlifetime settings which seems consistent with the issue. The PHPSESSID says it will expire when the ...
1
vote
0answers
57 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
0answers
87 views

Proper way/place to apply decorator pattern for view layer in mvc

I have an array of model objects containing data some of which is states represented by integers. In the view these states are shown as icons and tooltips. The tooltip is needed only in the view and ...
0
votes
0answers
44 views

“remember me” functionality but user database on another app on another sub-domain

I'm considering how to add remember me functionality to our app. However we have our app, and a separate app that handles authentication on another sub-domain. When authenticating from one of our apps,...
2
votes
1answer
101 views

Set authenticated users session cookie's to long term, but others to short term?

We want to extend the session duration for our users. I guess it doesn't matter for users who are not authenticated. We can create a PHPSESSID cookie for them and if it expires when they close their ...
0
votes
1answer
123 views

Is it worth it to follow code conventions of Netbeans? [closed]

I am always not able to follow Netbeans default coding conventions like the following Function should be N lines only Method Length is N Lines (M allowed) Warning: Do not Access Superglobal $...
0
votes
1answer
105 views

Saving an image in MYSQL vs saving to a folder [duplicate]

Is there an advantage to either method and/or a risk to either? Looking to upload JPG or PNG files only with a size limit of ~3mb with reduction done before insertion.
0
votes
0answers
83 views

gearman or semaphore with symfony2

I want some way to store the user clicks on deals, categories and advertisements on symfony2 store. My situation: Basically, I am planning to use either messaging system using semaphore or integrate ...
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 &...
0
votes
0answers
40 views

Change API response with minimum code changes

My Application is built on Laravel and currently has the following components : Models Dictionary Word Controllers DictionaryController WordController It's a JSON API, so views are nothing ...
2
votes
0answers
192 views

How should I store usernames and passwords for user login using php/cassandra?

I am new to NOSQL and Cassandra. I am not sure if I should store usernames and password in Cassandra. If I should, what is the best way to do that? I am getting lots of conflicting ideas from research....
2
votes
2answers
234 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 (...
3
votes
3answers
280 views

Unit Testing and 3rd party packages. Do I mock or not?

I'm just getting used to unit testing and on my new project I decided to adopt a TDD approach. My code below is to test the UserServices class which is responsible for creating a user, deleting a ...
1
vote
2answers
74 views

Does my code still break encapsulation and uses getters/setters instead of the TellDontAsk principle?

I and one guy have been discussing potential solution of a problem on an unrelated board, regarding the typical getter/setter hate, ie. using getters/setters leads to procedural programming. I ...
0
votes
1answer
257 views

Why use PDO's rowCount() if I can just use PHP's count()?

So in PHP, there's PDO to fetch things from a database. Now I see a bunch of $stmt->rowCount() calls in the code I'm working with. Why not just fetch the result array and throw a PHP count() over ...
0
votes
1answer
105 views

Best practice for settings for PHP class for code generation [closed]

I would like to have a class creating any code from given options and output it in a chosen way. I have written class for generation of simple JavaScript code for such cases where is needed to ...
0
votes
2answers
188 views

Undo/redo implementation for file changes in PHP

I was thinking to store all file operations inside an array, along with the reverse operations which are used for undos. Example: [ [ 'op' => 'move', 'parameters' => [$path_from, $...
2
votes
1answer
89 views

How far do I, or can I take TDD tests with Service Objects?

In writing PHPSPEC tests for a Zend Framework 2 application, I'm left wondering how far to 'dig'. Consider this very simple case: A DomainService (Domain in the URL sense of the word) should be ...
2
votes
1answer
417 views

Consuming REST services: client or server

I am working on a new project in which we are currently deciding which technologies and frameworks we will be using. The application will eventually be cross platform. Therefore, for the server side, ...
14
votes
3answers
4k views

Is it good practice to avoid warnings and notices?

I've generally been working with PHP warnings and notices off, since I work on a lot of projects where it's already in live production. Now, if I turn on the warnings and notices on these live ...
0
votes
1answer
67 views

static method, helper function or in the controller, where does this go?

I'm working on a piece of functionality that simply allows a guest user to perform an action a certain number of times before requiring them to login\create account. In this instance, they can vote on ...
6
votes
6answers
281 views

Should I always store parsed data in database before manipulating?

I am about to start a new project which involves taking an excel file, parsing the data (php-excel-reader) and then using the parsed values in a HTML email. My question is pretty simple. Is it better ...
0
votes
1answer
206 views

Confusion over Node as a “script” vs Node as a “server”

As I was beginning to tool around a bit with node, I was told that I needed to undergo a little bit of a paradigm shift since I was coming from a PHP background. I would ask questions like, "I have my ...
0
votes
1answer
126 views

Strategy for Public / Private API, Encrypted (or Hashed) Data, and Server Compromise

In this very simplistic but realistic scenario, I have 2 combo web/database servers (A) behind a load balancer and a single IP address. They also permit access only from one IP address -- the client (...
8
votes
1answer
209 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 ...
3
votes
2answers
183 views

How are POST/PUT/DELETE data passed to APIs?

I know that the data is passed through HTTP, but I'm not sure if I should be passing data through HTTP headers, or HTTP bodies. Which one is the convention for APIs? Also, theoretically using PHP, ...
3
votes
2answers
404 views

Implementing “buy one get one for free” coupon logic for shopping cart

Trying to solve bogo coupon logic with proper design pattern, but having trouble identifying one. Use case: "Buy iPad get SmartCase for free" Suppose we have the following objects: Product: - ...
2
votes
4answers
299 views

How to properly reverse the if statement when you have two conditions in it?

In PHP I have this if statement ( $first and $second will evaluate to true or false): if ($first && $second) { // evereything is OK } else { throw new Exception()... } My real code ...
3
votes
3answers
179 views

Are exceptions only for handling errors?

I have a script that throws exceptions when something goes wrong. However, for the purposes of testing I also want to capture specific points although I'm not sure whether they would be deemed errors ...
0
votes
1answer
560 views

Is PHP7 a static or dynamic typed language? [closed]

In the past few years, we've been using dynamically typed versions of PHP. However, in PHP7 we have an option to enable 'strict types': PHP RFC: Return Type Declarations PHP RFC: Scalar Type ...
0
votes
2answers
176 views

How to analyze a code of a web application which is running? [closed]

Joshua Bloch said in an interview that the best way to know and understand code written by others is to read it, mentally or through a debugger. Well, my question is this: is it possible, through a ...
0
votes
2answers
107 views

How to simulate method overloading in langs without such feature? [closed]

Langs like Java knows about true method overloading: class Overload { void demo (int a) { System.out.println ("a: " + a); } void demo (int a, int b) { System.out.println ("a and b: " + a +...
1
vote
0answers
244 views

Can this be used to implement Post Redirect Get pattern?

I am trying to implement proper a Post Redirect Get on a PHP site (question is language agnostic in nature however). I thought about it, and realized that running this code on every request seems to ...
0
votes
1answer
133 views

Why use PHP_AUTH_USER instead of taking credentials under post method

What would be the advantages of using PHP_AUTH_USER and PHP_AUTH_PW instead of the verifying the credentials under method - post . Why i should use: $_SERVER["PHP_AUTH_USER"]; and $_SERVER["...
1
vote
1answer
71 views

How can I create a client for a service without hiding the parameters needed for each endpoint?

I'm creating a client to a third-party soap web service in my application. Here is the way I'm thinking of doing it: Create a ClientFactory that makes a client based on the wsdl file, and sets ...
16
votes
2answers
1k views

Is it a good idea to define one big private function in a class to maintain valid state, that is, to update the object's data members?

Although in the code below a simple single item purchase in an e-commerce site is used, my general question is about updating all data members to keep an object's data in valid state at all times. I ...
2
votes
2answers
185 views

Is equating a variable to a function that takes the same variable bad programming?

Is it improper programming to set a variable equal to the result of a function that accepts the same variable? The languages in question here are c#, javascript and PHP (not sure if this works in C ...
3
votes
1answer
367 views

why use authentication token instead of session_id for app(android side) in REST API

in normal php web application after login we use session_id that came from web browser to check if user loged in or not. But in REST API authentication I read some tutorials that say php should send ...