PHP is a widely-used, general-purpose server side scripting language that is especially suited for web development.
21
votes
5answers
759 views
Instantiating objects with many attributes
I have a class with quite a few attributes, most of which are known when I create an instance of the object. So I pass all the values in the constructor:
$op = new OpenIdProvider($imgPath . $name . ...
18
votes
3answers
640 views
Better separation of programming and presentation logic
I'm struggling for a while now with the readability of my code, I after I tried to get as much insight as possible (for my standards). On my level, I think I understand and use it all right for my ...
17
votes
7answers
1k views
Is_numeric_array() missing!
I found that in PHP (or i probably can't find it) a proper is_numeric_array($array) function is missing. So i created one. The problem is that i don't think it's great and i don't know how to improve ...
16
votes
5answers
3k views
Database connection in constructor and destructor
I am playing with different ways to do database interaction in PHP, and one of the ideas I have been playing with is connecting to the DB in the constructor and disconnecting in the destructor. This ...
15
votes
2answers
795 views
Small PHP Viewer/Controller template
I have written a small template Viewer/Controller esque library that I would like some critiques on.
The library is located here
If you are looking for where to start, check out App.php and ...
12
votes
3answers
5k views
CodeIgniter Active Record Subqueries
I use CodeIgniter at work, and one of our model files had a lot of subqueries in it. I originally had to manually write each subquery, and wondered if I could use active records instead.
So, to make ...
12
votes
4answers
812 views
PHP and Javascript work together to create a DRY mess!
Consider the following. It's a simple list of items in a list, which allow the user to dynamically generate that list of events. Then a controller action does the work of serializing that into the ...
11
votes
6answers
2k views
Good Practice: Loop And If statement
I'd like to know what is the best practice:
version A:
loop1
if condition1
code1
if condition2
code2
if condition3
code3
Or, version B:
if condition1
loop1 with code1
if ...
11
votes
3answers
2k views
PHP PDO Database Abstraction Layer
I'd like to get some feedback on a PHP Database Abstraction Layer I've created. It's a little long, but there really wasn't a way to just post part of it. Here is the base DBObject class for MySQL:
...
10
votes
3answers
2k views
Calculate a median - Too much code ?
I got this as an implementation of "get me the median of those values". But it sort of doesn't feel right (too long, too many branch points) so I thought I'll post it here to see what you think. :)
...
10
votes
4answers
967 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 ...
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 ...
9
votes
4answers
1k views
Best practice in php for “If the variable is empty, set a default value”
This is the pattern I've been using for "If the variable is empty, set a default value", and for variables like $muffin it has all seemed well and good. But in the following real example this pattern ...
9
votes
4answers
545 views
Checking date & time in php
Goal: To create a countdown to our next available live stream.
Details: We live stream six times a week all (PST).
1. Sunday at 8:00 a.m.
2. Sunday at 10:00 a.m.
3. Sunday at 12:00 p.m.
4. Sunday at ...
9
votes
4answers
241 views
How to improve this to a readable Unittests that explain the Class better ?
for starters i though of going with a mostly code only example.
This shows a testcase for an old caching library i use for a project. It features simple save/load/delete functions (saidly static ...