Skip to main content
9 votes
Accepted

How to use PHP Visibility method?

Yes, the original code is awful. It is 200 lines of spaghetti code; I have no idea what it does, it is impossible to reuse and extremely difficult to test, debug, or change. That doesn't necessarily ...
tim's user avatar
  • 25.1k
7 votes

Registration code

The code is horrible. It probably contains all of the top 10 vulnerabilities listed on the OWASP web site. It uses a programming language that is well-known for its bad security history and its ...
Roland Illig's user avatar
  • 21.3k
6 votes
Accepted

A Search Engine Class

I really like the structure of your code. That said, I almost never suggest to give class variables default values. That is what the constructor is for. For that matter, you don't need to specify that ...
Trojan404's user avatar
  • 818
6 votes

Registration code

I am bit puzzled by strip_tags: ...
Kate's user avatar
  • 6,983
6 votes

Security of post submission, picture upload and post fetch

Please read about sql injection. Basically you should be using prepared statements with parameters for executing SQL queries - either PDO::prepare() or ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
5 votes
Accepted

PHP Class code that allow developers to register taxonomies in a CMS

I think you're mixing too many ideas here and as a consequence your class ends up having too many responsibilities, which than need extensive documentation because their behaviour may not be obvious ...
matchilling's user avatar
5 votes
Accepted

PHP class which preserves line break by splitting the line into as many line break as it have

After about 10 minutes of reading your code and testing it out, I think I figured out what your class is supposed to, which is not a good sign for such a small class. To me it seems that the goal of ...
Thijs Riezebeek's user avatar
4 votes
Accepted

Authorizing users for POST requests

I do not see much thing to review, except goto. Code style... ...is OK. I will suggest functions to be no more than 10-15 lines, ...
Nick's user avatar
  • 1,582
4 votes

Doctrine/Symfony WHERE clause for reports

I would suggest using the QueryBuilder ...
Filip Procházka's user avatar
3 votes

PHP program which extracts attribute lists from custom tag

Here are some things I noticed: The function splitByDelimiter() is no more than a wrapper around explode(). Why not use ...
KIKO Software's user avatar
2 votes

Optimized solution for a rolling dice code puzzle

@Mr AJ already gave you a valid answer on the algorithmic approach in his Java example, but since it seems Java is unfamiliar to you, I will just write out the algorithm here in a way that hopefully ...
Mike Brant's user avatar
  • 9,628
2 votes

Optimized solution for a rolling dice code puzzle

With extra O(n) space the complexity can be made O(n) only, without sorting that will take ...
Mr X's user avatar
  • 173
2 votes
Accepted

php swiftmailer two message instances with one mailer instance?

Note: this is intended to be a Community wiki since it was taken from a deleted answer by yannis; The suggestion to do this was here Using two message instances is fine as is most of your code. There ...
2 votes

is_numeric_array() is missing

This is an old post, but if you're looking for a shorter but still elegant solution, use this: return array_values($array) === $array You could even use it as ...
humdash's user avatar
  • 21
2 votes

Parsing multipart/form-data in php for PUT requests

Based on your work I derived the following code from it. The previous code had for example problems with multiple attached files. Also I would avoid setting the ...
Michael's user avatar
  • 21
2 votes

Bulk customer creation

Initial thoughts on this code: one long and very convoluted chunk. It badly needs refactoring into smaller and more easily understood pieces. various commented out lines, which obscure the logic. SQL ...
rivimey's user avatar
  • 121
2 votes
Accepted

Forum project using OOP PHP

back: I'm not sure what this function is used for (and the name doesn't seem that great), but it is open to XSS. An attacker could create a page at ...
tim's user avatar
  • 25.1k
2 votes
Accepted

Lookup class to get descriptions of values

Having provided an answer to your previous review, I have a mixed bag of reactions towards this latest version. The good: You seem to have embraced the concept of data validation (though ...
Mike Brant's user avatar
  • 9,628
2 votes

Lookup class to get descriptions of values

Getting a distinct list from MySQL would slow things down quite a bit, I wouldn't do that. Perhaps you're overdoing it a bit? Yes, it is always good to filter user input, but I would do that at the ...
KIKO Software's user avatar
2 votes
Accepted

PHP program which extracts attribute lists from custom tag

My function does not use hard-coded attributes, so it is more flexible than yours. It's also just a few lines of code (I think you made things over-complicated by having very thin wrappers for ...
BeetleJuice's user avatar
2 votes

Create multi-dim array from cursor

You are asking if you can speed up the assignment into the array? I don't think you will be able to get a notable speed improvement on this part no. This should be completely negligible compared to ...
Milney's user avatar
  • 230
2 votes

Finding a word with the most occurrences of a character

arr and array These arrays have too similar names. It's better to avoid using too similar names, to avoid confusion and ...
janos's user avatar
  • 111k
2 votes

Split words that are too big

I would think a better approach might be to identify location of spaces in string and look for cases where there is index position > 40 between these spaces, and then to insert the space into the ...
Mike Brant's user avatar
  • 9,628
2 votes

Split words that are too big

Normally I take the time to study Mike Brant's answers (because they are so frequently educational to me), but this time it was tl;dr. If this was my project, I'd specifically/exclusively target the "...
mickmackusa's user avatar
  • 8,674
2 votes

Combining json responses of recursive web service calls with PHP and curl

public static function CallAPI($method, $url, $data = false) Use lowercase first letter for method and function names. callAPI....
Mike Brant's user avatar
  • 9,628
2 votes

PHP handle array when query database with one-to-many relationship

First, let's start with the way your query is formatted. I would strongly recommend you get in the habit of breaking your query across lines when they get long like this. I oftentimes use heredoc/...
Mike Brant's user avatar
  • 9,628
2 votes
Accepted

Create an object when you need it! in PHP

Your App class seem too broad in purpose. Right now it: Acts as a sort of global key-value store. Acts as a registry of "core" classes used in an application. ...
Mike Brant's user avatar
  • 9,628
2 votes

Code for a Person DTO, with tests

In the tests (and anywhere else), you should use constants to ensure correct spelling of the properties : ...
Geompse's user avatar
  • 121
2 votes

Which is cleaner: a constructor with many parameters or many setters after construction?

Where do you want to validate the parameters? If the parameters are passed inside the constructor (either as multiple parameters or as a structure), the constructor can check all of them and throw an ...
D. Jurcau's user avatar
  • 3,010
2 votes
Accepted

Function to insert a tag into a database

Use a transaction, so you won't need all the manual delete queries Use shorter PDO syntax. Log errors Use prepared statements In the end it should be like ...
Your Common Sense's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible