0
votes
1answer
42 views

best practice in use of if statement followed by another [closed]

suppose I need to use loop statement just after the if condition as bellow, if(true){ foreach ($arr as $value) { echo $value ; } } and also i can ...
3
votes
2answers
68 views

Is this following Separation of Concerns and PHP OOP standards?

I've been working with PHP for a while now, but unfortunately haven't delved into the OO side of it until recently. I've been reading up on separation of concerns and OOP best practices, and I think ...
3
votes
1answer
138 views

Is this right structure for MVC / MVP application?

I have written a code for an application/website that I wanted to be structured similarly to MVC design pattern (but I think it's rather MVP based on comparison I read). This functions as a kind of ...
5
votes
1answer
346 views

How is OOP achieved with configuration files in PHP?

Someone asked if their singleton is good for OOP: Using a singleton class to get and set program wide settings. However, the answer just provides tweaks to his existing code - but the question ...
12
votes
3answers
233 views

Prepared statements from security viewpoint

I've decided to go with OOP style and prepared statements, and so far I like it a lot more than the procedural style. It's much more understandable in my opinion. For this code review, I've just ...
5
votes
2answers
128 views

PHP framework building: Sessions Managment Class

I am building a PHP framework and would like to get some feedback on a few different sections of the project so far. I consider myself still a neophyte in PHP so I would like to ask if I'm going about ...
5
votes
1answer
127 views

Best Practices concerning Includes and SQL Connect Strings

I'm just starting to learn PHP. I have three random questions about PHP and one question about Code Review. None of them are technical questions ("will this work?"); they're best practices questions ...
1
vote
2answers
104 views

Is calling a function from within another to alleviate code duplication the best solution?

I am writing up a class to handle various templates to be used in a web application. Each template contains various placeholders which will need to be replaced at the time of the build. I a wondering ...
1
vote
1answer
65 views

Copying a lot of code to filter four PHP arrays

I have made this search filter and it works fine, but I think the code looks a little messy and I have no idea how to clean it up. I hope the following makes sense, otherwise please tell me which ...
1
vote
1answer
55 views

Pushing instantiated class in an array

I've just stumbled upon something today that seemed "unethical" in PHP. What I originally thought as malpractice, turned out to work just fine. Basically what I was wondering is if pushing an ...
0
votes
2answers
50 views

Building a string made easier?

I have these lines of code in my view: ...
1
vote
1answer
147 views

Feedback on a small PHP function that generates JSON data

I wrote a PHP function that generates JSON data to populate a line graph. Through jQuery, my code uses a GET request to the PHP script to fetch the JSON data. An example of the JSON data is as ...
0
votes
0answers
298 views

Delete function for Codeigniter Controller

This is my delete function that I will be using for most of my other controllers that need one. The purpose of this is to delete the value that passed in to delete ...
2
votes
1answer
186 views

Trying out my first User Registration script

I am trying to write my first script that checks users against a database (MySQL right now) and if they aren't in the database, registers them. I've tried my best to sanitize and validate the form ...
1
vote
1answer
62 views

How to use the value of a method result based on a test?

I have some Java like this: if (!fooclass.getInfoText().equals("")) { this.setInfoText(fooclass.getInfoText()); } Is there a neater way of setting one value ...
0
votes
1answer
176 views

DB Query within foreach, non-elegant code in general?

I'd like a general opinion on my piece of code (which does exactly what I want it to do). I feel like I'm using bad practices, like a DB query within a foreach loop, or grabbing the lowest value in a ...
1
vote
1answer
94 views

Could my object use static methods? Anything I need to do to make the code better?

With the Zend coding convention in the back of my mind, I have set this up. It lets you communicate with the API of the vendor TargetSMS. They allow you to bill ...
2
votes
1answer
1k views

PHP framework building: Database Control Classes

I am building a PHP framework and would like to get some feedback on a few different sections of the project so far. I consider myself still a neophyte in PHP so I would like to ask if I'm going about ...
1
vote
1answer
264 views

If statements in validating different form data types

I am using if statements within my functions to validate form fields and then on the isset event. I want to be able to create many different functions to validate various fields groups and it seems ...
-3
votes
2answers
245 views

What is better and faster? Should I use is_null or $var === null in a if statement? [closed]

I was thinking about is_null and $var === null in my if control structures. Here is a small ...
5
votes
2answers
121 views

OOP approach to using DOMDocument

I've tried to write an "OOP" approach to printing a website using the DOMDocument class. I'm kind of stuck here because I feel like I am blundering in how I am passing and using the DOMDocument. I ...
2
votes
1answer
100 views

Practical advise for CMS

I'm working on a CMS system. The basis is pretty much done but before going any further I would like to know if there are things I really should change in the way I code things. I am pretty sure ...
3
votes
4answers
447 views

Best practices in PHP

I've posted here before and got pretty helpful reviews. So, how does my code look now. To keep it really helpful, I just copied this from the middle of one of my projects. Review please? ...
1
vote
1answer
113 views

Referring to nested arrays and array_merge (php)

In such an array: ...
1
vote
1answer
180 views

Getting familiar with OOP - Factories

I have no idea if I'm doing this efficiently, or ideally, but I've written what I think is a factory. Please help me understand if this is good practice, or if there is another direction I should take ...
3
votes
2answers
131 views

How can this this URL Checker be made cleaner?

I have a table full of URLs, some of which will occasionally become invalid. As part of a system I'm writing to go through the links periodically, and test if they are valid (or redirect to valid ...
2
votes
0answers
260 views

CakePHP Best strategy for getting HABTM data in multiple ways within the same tool

School HABTM AthleticDirector I am building a tool for assigning athletic directors (ADs) to schools. The tool has a school menu/filter which, when selected, shows a list of ADs already assigned to ...
3
votes
2answers
854 views

PHP PDO Factory Classes

So, my question is more of a 'best practices' question rather than a question with a particular aim. This is my current understanding of PHP factories and how to incorporate them into a project using ...
0
votes
2answers
649 views

Consistent implementation of PHP class constants (arrays not allowed)

I'm currently writing a class: ...
11
votes
4answers
5k 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 ...
1
vote
3answers
678 views

PHP - Deleting Directory Contents & SubDirectory Contents

I've set up some PHP to delete a directory, it's contents, and any subdirectory and its contents... I'm new to PHP so I'm most definitely doing something WRONG or am doing something in the most ...
4
votes
1answer
4k views

Better way of handling data returned from fetch_assoc() (mysqli)

So I connected to the db, pull the data using fetch_assoc() (fetch_all(NUMB) is not available on the machine we are working with else this would be less of an issue). So I get the returned data and ...
3
votes
1answer
147 views

How can I improve my PHP model for my HTML5/JS mobile app?

I am posting the a section of the model of my application. Any/all feedback would be very helpful as I am trying to build my PHP skills, but I will ask a couple specific questions that might help ...
0
votes
2answers
410 views

How can I improve my PHP backend for html5/js mobile app?

I would really appreciate any feedback on the back-end of my mobile application. I tried to keep an MVC pattern, where I considered the app to be my view. Perhaps an REST framework would have been ...
12
votes
4answers
10k 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 ...
2
votes
2answers
2k views

Getting Facebook comments count via FQL

I'm currently getting the Facebook comments count over a query request to the Facbeook api. The problem is, there are about 15 queries on each site which makes it real slow to load (up to 6 seconds) ...
3
votes
3answers
278 views

Database output function

Please review the following code and list all the coding errors and poor coding practices that you can see in this code. ...
1
vote
1answer
79 views

contract validation and responsibility without exceptions in the constructor

my question is based on this "principles" do not throw exceptions in a constructor single responsibility / seperation of conerns use logic exceptions for broken contracts and runtime exceptions for ...
2
votes
1answer
98 views

Organizing a wordpress template with lots of variables

A question of organization and best practices with Wordpress templates: Where should I put my variables? Directly in the template? In a separate file via ...
4
votes
1answer
421 views

Entity collection best practice (separation of concerns, dependency injection, …)

I build a collection to ensure only valid entities in an array so I don't have to validate after every function / method call as I could rely on the collection to have only valid entities stored. ...
1
vote
2answers
5k views

Remove last word from string

Any suggestions on better way to remove the last word from a string? ...
2
votes
1answer
163 views

Twitter scanner

How can I script this in a better way? ...
1
vote
1answer
262 views

Browser freeze - How to handle or optimize 50,000 rows in one HTML select element more than several times?

I have an increasing table which already has records of 50,000+. So in a combo box I have to load it, so that it shows which one is selected and its a main record which need to be selected and based ...
5
votes
1answer
1k 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. ...
4
votes
3answers
7k views
2
votes
2answers
5k views

Review my PHP Login Class code/script

I wrote this PHP Login system and I would like to see if I have any errors/made any mistakes or if you guys think I can do something to improve it like including tokenizing for example and improving ...
6
votes
2answers
245 views

Is it bad practice to rely on short-circuit evaluation instead of using the IF control structure?

Examples of where I've started migrating to short-circuit evaluation: PHP ...
2
votes
1answer
597 views

Magic getters/setters in PHP … Any comments/suggestions?

So, I'm playing around with PHP, trying to write a small ORM. Having worked with Magento quite a bit lately, I've fallen in love with the automagic getters/setters that Magento, I think, inherited ...
6
votes
4answers
354 views

Truthy assignments

I often argue with the voices about the correctness of having assignations within an if statement (or equivalent), meaning having this: ...
1
vote
2answers
5k views

PHP - create a new user into a db using MVC framework

All, I am a beginner and am creating a small web app. I'm working on the registration process for new users, and as this is largely a learning project I'm doing it from scratch. Here is my user ...