Tagged Questions

The fifth version of the PHP: Hypertext Preprocessor (PHP) scripting language. It features the Zend Engine 2, better object model support, and many other improvements over PHP 4.

learn more… | top users | synonyms

1
vote
1answer
43 views

How to optimize the pagination query?

This is completely optimization question, I have a pagination query like that $this->paginate = array( 'fields' => array( 'DISTINCT Contact.contact_id', ...
6
votes
0answers
134 views

Thoughts on my brainfuck interpreter?

Had some free time this weekend and I hacked together a small Brainfuck interpreter, with the sole intention of explaining PHP's flavour of OO to a friend. This is a bit over-engineered on purpose, ...
1
vote
0answers
51 views

Simple event mediator

I was trying to explain the mediator pattern to a new developer, and ended up writing a simple event mediator. Thoughts? EventMediator class EventMediator { private $events = array(); ...
2
votes
1answer
70 views

First steps with PHP OOP

I am learning OOP using PHP5 and I wrote two simple classes for receive data of database using dependency injection pattern and render a grid with Twig. Please, if is possible, take a look and give ...
1
vote
1answer
61 views

Suggestions for improvement of HTML table building function

User specification "var_dump($GLOBALS) is ugly as ... without wamp" General specification Produce a PHP function to display the contents of $GLOABLS in a user-friendly manner Must produce ...
0
votes
2answers
66 views

Image upload script

Listening to mseancole's advice in my previous post, I have rewritten the code. function fihHomeIndex() { global $conf, $DBH; if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') { ...
2
votes
1answer
200 views

Image upload script in PHP

Hello users of codereview, I have written a basic image upload function that handles up to five file inputs, in PHP, intended to be hosted live on the internet very soon. As far as I know it's ...
1
vote
1answer
40 views

Using static for class default properties

I have made a class for generating html form elements: class input { public $tag = 'input', $type = 'text', $customClass, $name; public function __construct(array $cfg){ if ( ...
1
vote
1answer
78 views

Builder & decorator patterns together, am I doing this right?

Little background: payload is the representation of a message being send, using a specific transport. The builder pattern is used to build different representation (as array, or as a Swift_Message ...
0
votes
1answer
167 views

Routing done in php

I've written a small routing system in PHP but I'm not sure if it's done the right way and what changes can they be done to the code and improvements. Thank you very much for your help and time to ...
10
votes
4answers
764 views

How would a senior PHP developer design this Login class?

I incorporated the feedback I received from my previous post into a very simple Login class. Main question: How can I design this class and it's implementation so that it looks like it was ...
0
votes
2answers
70 views

methods in the class so close in what they do

I have this class that has these two methods that are so closely related to the each other. I do not want to pass the flags so I kept them separate. I was wondering if there is a way to rewrite it so ...
3
votes
3answers
160 views

PHP Simple OOP Class

I am still learning OOP and I need a little help, I don't really know how to properly make this not look so terrible. Any thoughts? <?php class Noti { public static $app; public static ...
3
votes
1answer
66 views

code review for this method

This method recieves an array of data and does some stuff in database. Need to get some review on it if possible public function doSomeStuff($arr = array()) { $id = ...
4
votes
2answers
205 views

Validation Class - Feedback Welcome!

I have written a Validation and Form class in PHP. Validation class allow you to define the rules of each field and a error message. Form class allow you to get a error message and also allow you ...
4
votes
1answer
280 views

Comparing multiple fields from two tables, looking for matches, updating 2nd table

In my never ending quest to improve my coding skills I am requesting peer input on the following code logic. I am asking because I'm -NOT- an expert, but would like to be one day. Source material and ...
3
votes
1answer
372 views

How to improve Try…Catch Block for PDO?

I have written a PDO wrapper and a class file like a model. So far, it's looking so good! I am just confuse where I should put Try...Catch block - Would it be better to place in PDO wrapper ...
5
votes
2answers
114 views

When an object has different representations… what's the OO pattern?

I've an AbstractMessage object (a hierarchy, actually). It represents a small text message and can be sent using different transport methods: HTTP, REST and a "mailer" transport. Each transport relies ...
1
vote
1answer
68 views

How to improve a file access permission/deny function?

I've quickly made a function to deny or allow access to files that are only used thru Ajax Calls. Key Generator /** * Generate a key for file access permission * * Function that returns a key to ...
4
votes
2answers
123 views

Would be possible to refactor this PHP code more?

I really don't like the so many return statements. Anyone think that this could be refactored more? public function validate($value, Constraint $constraint) { if('' === $value || null === $value) ...
2
votes
2answers
60 views

Is this function properly structured, leading to a secure row insertion?

I have the following function to insert a new row into a table: /** * Insert row into the designated table * * Function to add a new row into the designated table * * @param str $table ...
2
votes
1answer
69 views

How to optimize function that checks if a directory is empty when having over a million files inside?

I have the following function to confirm if a directory contains files: /** * Check if the directory is empty * * Function to ascertain if the specified directory contains files. * Comparing to ...
1
vote
1answer
249 views

PHP Config Class

I'm working on a config class for PHP, where I can easily bring in config options. Any improvements/suggestions are appreciated. Example usage: echo Config::get('database.host'); // Returns: ...
9
votes
4answers
1k views

Looking at this code, would you say I'm an OK coder?

Looking at this code, would you say I'm an OK coder? I just created this during a live screencast. The people who were on there were very very very critical of almost every line of code. They say I ...
0
votes
1answer
132 views

Optimizing blocks-maze generation script php [closed]

I created script that generates maze or some kind of dungeons that looks like this: http://s13.postimage.org/4uify3jxj/blocks.jpg I have problem with optimize, because when I've tried to add blockade ...
1
vote
2answers
128 views

Fun with conditionals (i'm bad…)

Yes, i'm bad at conditionals. I don't use it so much and i feel a bit lost with them. How would you (if possible) refactor or change this little piece of code? Second improved version: ...
1
vote
2answers
112 views

Code review for my class

I have made this class that runs a query. I want to optimize my code and want to have some expert advice Here is the class: class testClass extends Model { protected $_var1; protected ...
1
vote
0answers
47 views

Is this a sensible form iteration pattern for a web form with an unknown number of fields?

I'm designing a small intranet-based time-tracking web app that accepts an unknown number of data "rows" which each consist of 7 form fields. Rows can by dynamically added by the browser. Can I do ...
0
votes
1answer
55 views

What are the ways of updating a database automatically? [closed]

I have an RSS reader project and I need to update my database automatically. I have used cron but I have to set new crons every time I have new links and it also get me stuck because of too many cron ...
1
vote
1answer
181 views

PHP 5.4 Event System, just looking for general feedback

So I decided to create a trait that I could add to my classes that would add a simple way of binding functions to an event, and to fire those events. It ended up going a little further than I expected ...
0
votes
1answer
235 views

Using tumblr API via php [closed]

I want to work with the tumblr API, however it looks like I failed at it yet. Do you have any clues for me? <?php /** * User: dmendek * Date: 18.07.12 * Time: 16:09 */ class tumblrClass { ...
4
votes
2answers
249 views

PHP MVC controller code needs diet?

This is the dashboard controller code in PHP Symfony 2. It collects some aggregate data and points for charts, but i don't like it very much. Do you think that this code belongs to what a controller ...
1
vote
1answer
165 views

PHP Lazy loading with __get - yay or nay?

I have my own PHP MVC framework that I'm iteratively developing (i.e. adding a feature when I have the time). I'm trying to keep it to the best practices I can, while still adding the most in terms of ...
5
votes
5answers
734 views

Modifying an array during a foreach loop

This question is always on my mind. I usually alter the array while looping through its keys, based on my gut feelings: foreach (array_keys($array) as $key) { $array[$key] = ...
1
vote
1answer
689 views

how to properly use database connections in PHP classes

I need some advice\suggestions on how to create\handle database connections for a project I'm working on. I'm creating a simple work order system for my company using PHP 5.4.3, right now there isn't ...
4
votes
2answers
177 views

Variable parsing PHP

I written a class for loading an template file and replacing the variables with actual data. Please review my code and suggest me the best code. My Code: <?php /** * This class will helpful for ...
2
votes
3answers
106 views

PHP spl_autoload_{x} class, reviews welcome

Having spent years writing procedural PHP (albeit with a moderate understanding of OOP from Java) I took the plunge and have attempted to write an autload class for my PHP applications. I do have a ...
1
vote
1answer
160 views

What to do about this horrendous code?

I'm an experienced developer myself but for a current project I am working on I have decided to hire some developers to develop a mobile app which requires some supporting web services (developed in ...
0
votes
4answers
447 views

Review of my PHP framework, vervPHP

My goal with vervPHP was to create a framework I could create applications in very quickly, without any excessive configuration or over the top framework. Here's a link to the github, to see more: ...
3
votes
1answer
263 views

How to convert my classes to Dependency injection?

I am still learning to develop my skills in OOP. It uses a combination of the factory and its real singletons? As I did more research, I have realized this design pattern is bad because of global ...
2
votes
1answer
1k views

Is This the Best Approach for Unit Testing My Symfony2 Service?

The Service: <?php namespace TestApp\Services\Ext; class ExtFilterParser { private $parsedFilters = array(); private $filters = ''; private $requestParam = 'filter'; public ...
3
votes
1answer
301 views

Clumsy PHP5 code reading from an SQLite3 database

Some time ago I wrote myself a simple blog. The index page is generated with PHP5, using an SQLite3 database via the variable id handed to it via the URL. The SQLite database contains a table called ...
2
votes
3answers
514 views

PHP Socket Server

This Socket Server should handle about 5000 lines of log file entries per second from at least 15 machines from same network. Any tips to further optimize this script or are there any big mistakes? ...
2
votes
2answers
609 views

Need advice for my simple shopping cart's database structure

I’m trying to make a simple shopping cart application in PHP and am unsure of how to structure the database. I believe there are three tables that I need (but I could be wrong!): 1. products table ...
2
votes
1answer
353 views

OOP MySQL connection class

Under sage from another CR post I'm crafting an OOP MySQL connection/query class. Nothing new, but a place to start plying OOP PHP. Here is the current design,what would aid speed and portability? ...
4
votes
1answer
367 views

Prepared statements syntax review

Migrating to using prepared statements and would like some feedback on CRUD modules, concerned with syntax (usage and DRY) and speed: START: <?php // This page is for deleting a user record. // ...
4
votes
1answer
184 views

Is this code efficient?

I was wondering if this was a decent way of handling this function. Please take a look. // Use Less Mixins from Theme Options to adjust Stylesheets before Parsing Less to CSS add_filter( 'less_vars', ...
3
votes
0answers
756 views

Using ZF2 Event manager to save a model

I have been reading about ZF2 EventManager for some time now and I wonder what you'd think about this approach. class Model_Member extends App_Model_Model { protected $_data = array( 'ID' ...
1
vote
1answer
238 views

Improve code of BDDs in phpunit

no one in my team knows how to write BDD tests, so I started writing some and its quite working well for but I think the time has come to improve the code quality. Here is my code and it contains a ...
1
vote
1answer
66 views

is there a better and short way to getting that array from joined sql query and converting it to superfish dropdown menu?

I'm trying to build a superfish dropdown menu from a sql query. Working example is can be seen from here check the "emlak bul" category: ...

1 2