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

learn more… | top users | synonyms

6
votes
1answer
119 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
0answers
78 views

Run code once at deployment and never again. Possible? [on hold]

For any web applications, there are 2 stages, 1st, before request processing; 2nd, starting to process the request and further. And there are plenty of cool frameworks out there, viz. laravel, CI etc. ...
4
votes
1answer
410 views

How to make clear that a method can be overridden?

I have a library that I use in several applications. It has a method that returns a URL: class UrlBuilder { public function url($config) { $config = do_some_checks($config); return ...
0
votes
1answer
73 views

Different instances on deserialization of php objects?

Suppose I have a class called MyClass, with a member variable 'var'. And the following scenario: echo '<pre>'; $x=new MyClass; $y=new MyClass; $x->var=$y; echo 'Checking for ...
-5
votes
0answers
38 views

Send scheduled emails with conditions

I have to edit a Laravel project and add a function to send scheduled emails with certain conditions. Basically the project is about a ticketing system with which some companies have to interact. An ...
1
vote
0answers
20 views

Where does export file code belong in an MVC implementation that is designed mainly for HTML

I have an MVC website set up with a base view (Layout.php) containing HTML header and footer code. Other views (such as CarView.php) will extend this class. One of the methods in this class is ...
1
vote
1answer
61 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
votes
1answer
35 views

php base64_encode simplified answer

What are practical uses of base64_encode and base64_decode? At what particular situations are they used? For example, in terms of security? What is the usage of using this function when sending an ...
-3
votes
0answers
43 views

PHP display image on same page from DB with jQuery Ajax or iFrame? [on hold]

I have used separate solve.php because headers should be set before any echo statements. Requirement: To view image on the same page when click view. What I did: I coded already jQuery ajax method ...
-1
votes
1answer
139 views

Registration form with email verification

Can someone point me in the right direction: I need to make a website with a registration form, to create accounts with e-mail verification, to write the forms content in a database table or something ...
1
vote
0answers
75 views

Sending large amount of messages async

The scenario is this: I have web based service that does regular request processing and it's doing persistence into db etc.. Fast response to the client is crucial. So now the average request is about ...
5
votes
2answers
292 views

How to prevent multiple form submissions when user reloads the page

I'm currently working on a project which requires that we integration a 3rd party SOAP API to handle a number of basic CRUD type operations. Our current implementation allows us to leveraging the ...
0
votes
1answer
121 views

How to secure my authentication code?

I'm working a PHP project where I need to authenticate users to a portal. Just wanted to get your opinion on the code, statistics of the website show some strange behaviour with the login form. ...
2
votes
1answer
207 views

Help in writing more generic code

I'm doing a php MVC project using code igniter. I have two models, a and b. Each class contains four functions (insert, delete, update and view) and their implementations are almost the same with ...
-1
votes
0answers
9 views

Lets develop a session timeout! [migrated]

Important definitions: session.gc_maxlifetime - (default 1440 seconds) defines how long an unused PHP session will be kept alive. For example: A user logs in, browses through your application ...
31
votes
6answers
26k views

Naming classes, methods, functions and variables [duplicate]

There are 3 important naming conventions: with_underscores PascalCased camelCased Other variants are not important because they are not commonly used. For variables it seems that the one with ...
2
votes
2answers
231 views

Recommend an approach to decouple Product and Access code constructs, in order to simplify Product testing

I have some code that tightly couples Product specific code and Product-Access code. I am not sure how to untangle it. So for example, for testing Product, I have to mock up Access objects. And ...
-1
votes
1answer
51 views

Any Non-Singleton PHP PDO Db Connection Examples? [closed]

Are there any good examples of non-Singleton PHP PDO Dbfactory or connection classes people can point me in the direction, or perhaps even briefly illustrate. I am interested in learning both support ...
1
vote
8answers
651 views

Using error numbers which only work on 64 bit servers: a bad idea?

In an attempt to solve one problem I encountered another. I would like to have an easy and memorable way of creating unique error numbers, across projects and across developers. The scheme I came up ...
0
votes
1answer
81 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 ...
-2
votes
0answers
91 views

How to insert large text into a DB with PHP? [migrated]

I have a function that generates a random text with about 8,000 characters. This text is generated at the time of first access the page, based on some parameters. I would like this text to be ...
1
vote
3answers
73 views

Multiple items in a single column SQL

I'm creating a charter database structure. I'm trying to figure something out, I have read on here that databases should be normalized. Now, I'm a bit confused on this because I believe I have ...
2
votes
2answers
201 views

The best way of handing a form post as an API type of submission

I have recently been tasked with a project to create an API that handles a form post using PHP. I have never done something like this before and this will be handling payments so I would like to do ...
2
votes
1answer
1k views

Liskov principle: violation by type-hinting

According to the Liskov principle, a construction like the one below is invalid, as it strengthens a pre-condition. I know the example is pointless/nonsense, but when I last asked a question like ...
1
vote
1answer
93 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
1answer
160 views

Should I have code that only exists for testing?

I have a service class which is responsible for instantiating repositories and using them. It makes an external Http request which ideally I would like to mock for testing. However, I am not quite ...
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 ...
0
votes
0answers
92 views

Making code more “modular”

As an semi-experienced procedural PHP developer, my OOP still needs a lot of work. I am still working through SOLID principles and other theories and guidelines of OOP, and am stuck with something ...
2
votes
3answers
122 views

Is there any low level way to get shifted or unshifted bits which results from bitwise operations?

I was playing with bitwise operations and a question about counting true bits of any positive integer value, so I solved the problem with bit shifting, so I just thought if there would be some way to ...
-2
votes
0answers
21 views

Why is error suppression ALWAYS a bad thing? [duplicate]

It seems to be the general consensus that there are absolutely no scenarios in which an error should simply be suppressed, e.g. using the @ operator in PHP. But if, as an example, I want to do ...
20
votes
1answer
14k views

With PHP frameworks, why is the “route” concept used?

The reason I ask this is because isn't a PHP script a route? For example, if you have an article.php then your route is simply http://mysite.com/article.php. Why further abstract away the concept of ...
2
votes
1answer
162 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 ...
-2
votes
0answers
77 views

Database structure for an Android chat application

I have a structuring or rather designing problem. I am developing an Android chat application and I need to know if anyone has an idea on how the database should be structured to allow group and ...
0
votes
1answer
380 views

Should I use session or cache to keep the time it last polled when polling to server at intervals?

I'm building a web chat app using session to keep the time the app last polled so that the server can determine whether messages exist between the current polling time and last polling time. It works ...
1
vote
1answer
52 views

PHP Where do routes end and queries begin

I have a PHP app and 90% of the code is about managing multiple MySQL tables. But there are other systems like a User system and an Admin system, etc. All PHP requests are processed in one App file, ...
3
votes
1answer
100 views

Dependency Injection & In-class Instantiation | Practical Limitations

Dependency Inversion is Good Inversion of dependency is good, it: Simplifies unit-testing Reduces coupling, allowing software components to be used interchangeably Keeps instantiation logic for a ...
0
votes
3answers
525 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 ...
3
votes
2answers
289 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 ...
-3
votes
1answer
71 views

Is it possible for $this to return a __construct?

I am currently working on my PHP skills and at the moment I'm working with classes. What I want to do is to create a class for which I can echo the object. I have the following example: class ...
0
votes
1answer
516 views

Like structure table with Laravel and showing the most popular content at top

I am using Laravel to creating a website, my users can post questions and other users can write their comments under the post, each comment have Up vote and Down vote, and users can voting for ...
0
votes
1answer
100 views

Should “magic” getter functions be used for dynamically calculated values or just existing properties?

For example, if I had a Customer class and wanted to get all orders by them. Would it be better to do: class Customer{ public function getOrders(){ return results from db query } } ...
1
vote
2answers
234 views

Multiple instance of the same class?

I have a class named "Category" to handle all the operations and data about my categories. Now, my class is created however I need to find a way to build an object for each of the categories in my ...
-1
votes
2answers
152 views

Open source project - framework or core PHP?

I am working in some open source project in PHP. My question is, should I make it using some kind of framework, say Laravel, or in plain PHP, in a hope for a large no of programmers using it? Btw, ...
0
votes
0answers
14 views

PHP array implementation what hashtable's 'bool persistent' does stand for? [migrated]

I read So let’s just say that persistent specifies that the hash table can live between multiple requests. In Nikic's blog about PHP array implementation There is no further information in ...
-2
votes
1answer
58 views

Multiple arguments for last parameter

I have function that has three parameters, called key, value and attribute. Parameter attribute may be empty or have within two arguments. Code of function below is shortened (deprived of arguments ...
4
votes
3answers
223 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' => ...
2
votes
1answer
127 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 ...
0
votes
4answers
2k views

Is it bad to learn multiple programming languages? [closed]

I started learning PHP and I was able to get myself familiar with it. Now, I want to explore other programming languages like PERL so that I can compare it myself to PHP. Will I be confused to learn ...
0
votes
0answers
19 views

Routing with a crowded bootstrap

I'm developing a Hack application with a front controller. I've opted out of using a framework, and though my router is pretty naive, it's done its job. The highest-level components are in the global ...
0
votes
0answers
29 views

Clearing Laravel cache on REST web service and front-end

Our REST web service and front-end are both on the Laravel Framework. The REST service and the front-end share a memcached server. The endpoint response and the data received on the front-end are ...