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.
-1
votes
2answers
27 views
WebSite stucture with PHP [closed]
Can you help me to write my rewrite rules for this page.
When I write : contact.html?id=2
I want get : index.php?location=contact&id=2
That's my index page.
<?php
...
-1
votes
0answers
21 views
Include Multiple Database Connections Inside a PHP Class [closed]
I've a simple PHP class file and i Want to include multiple database connections, since each of my functions using different databases for fetching information.
The files to be included in the class
...
3
votes
2answers
66 views
Potential Problems with this templating technique
I like the way Zend Framework works it's views and I make extensive use of partials but every partial include results in it's own file system hit. As I'm building my own framework I thought I could do ...
3
votes
1answer
102 views
Improvement of my php code
I wrote a class with this function. Can I improve my code performance in the bottom of the function? I don't like the while loops!
public function loadFields(array $fields, $as_object = ...
2
votes
1answer
47 views
Can I do something better in that code? And improvements?
Hi guys, simple question!
Can I do something better with the code I wrote.
It's running problem less. It's just a snippet of a library I wrote.
Thank you for all answers!
<?php
/*
* ...
1
vote
1answer
59 views
array to return on conditions
I am writing a method to find me a price range for special price as well as the retail price. Such as in example below I have price range for retail from 129 to 329 where as special price range is 89 ...
0
votes
1answer
46 views
Should a User class only contain attributes and no methods apart from getters/setters?
I'm trying to improve my OOP code and I think my User class is becoming way too fat.
In my program a user has rights over "lists". Read, Write, Update, Delete.
So I made a User class
class User
{
...
2
votes
1answer
111 views
PHP - Alternated Caesar Cipher, code could be improved?
I've recently picked up PHP and due to having an IT-security class I tried out to code the first assignment in PHP.
The algorithm I took upon is an alternation of the caesar cipher, instead of using a ...
1
vote
1answer
41 views
Referring to nested arrays and array_merge (php)
In such an array:
$arr = Array (
[key0] => Array (
[subkey0] => Array (
[0] => "value0"
[1] => "value1"
)
[subkey1] => Array (
...
0
votes
2answers
75 views
Image Upload Script Security Review
<?php
$filename = $_FILE['inputfile']['name'];
$upload_path = 'images/';
//extract extension
$ext = strtolower(substr($filename, strrpos($filename, '.') + 1));
// return mime type ala mimetype ...
1
vote
1answer
50 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',
...
8
votes
0answers
220 views
Thoughts on my brain fart 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
55 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
88 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
67 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
81 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
242 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
43 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
104 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
193 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
1k 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
183 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
67 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
270 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
314 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
509 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
121 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
69 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
131 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
70 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
284 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
141 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
131 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
115 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
48 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
56 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
247 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
241 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
262 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
180 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
1k 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
1k 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
184 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
109 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
164 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
457 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
276 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 ...

