New answers tagged php
1
vote
Is this PDO query okay to use in PHP OOP?
Nope, this "PDO query" is NOT okay, especially "to use in PHP OOP".
The Database class does nothing useful, and shouldn't exist.
The Query class should never extend the Database ...
0
votes
Check if a new movie session can be inserted
You're focusing on aesthetics while missing the main problem:
$sessions = Sessions::get();
Presumably this selects all sessions in the database for this user and ...
0
votes
Check if a new movie session can be inserted
Do these get() and validateSession() methods both exist within the Sessions class? Perhaps ask yourself if you have a good ...
1
vote
Simple websocket chat app, security and efficiency concerns
There is no direct input into that line, but can't they just open console and go execute that function themselves?
Yes, but if I was a malicious actor, I would just take your websocket url and build ...
4
votes
Count each word within a string
Review
Mick has suggested a solution with fewer lines of code. I would like to address some points about the existing code.
Useless conditional
Inside the else ...
5
votes
Accepted
Count each word within a string
You can competely avoid rolling your own code for this task. PHP offers a solution via just two native function calls.
Ask str_word_count() to return all words ...
3
votes
Laravel 9 - Metadata creation using middleware?
Redis
If you really need to use specific data and you don't have other ways to do it you can use Redis.
Misc improvements
(Not sure if this works with Laravel 9) You also should not save direct URL ...
2
votes
PHP local document crawler
It is unfortunate that no answers have been received since this was posted more than 10 years ago. Perhaps you've learned a few things since then and/or the code has changed. Regardless hopefully the ...
1
vote
Codility cyclic rotation solution in PHP
solution may be an acceptable function name in a one-off coding challenge, but in a real application try to give your functions an intuitive name that describes its ...
2
votes
DB Class extending PDO w/ other useful functions
Given that all cosmetic suggestions were already given, I'd concentrate on rather critical flaws.
Architecture-wise, such a class shouldn't exist. Technically, it is not even a class at all, but ...
4
votes
OOP PHP form builder with validation
OOP
I agree with the answer by Kiko. You didn't ask about MVC code but if that is a goal then it would be wise to only have HTML/text output by the view components - e.g. either in FormGenerator.php ...
4
votes
Accepted
OOP PHP form builder with validation
This looks like proper OOP code. It doesn't just encapsulate a lot of functions in a single class. It's expandable with more input types and errors, but I am afraid that you might have overdone it a ...
2
votes
PHP assign values within in_array
I can't get clear answers to my question in the comments, but I think I can try something. It would seem logical to define an array that contains the days of the week, like this:
...
3
votes
Accepted
DB Class extending PDO w/ other useful functions
You didn't explain, in your question, what your objectives were with this class. Why encapsulate a PDO class like this? My guess is that you did this to put all your database functions in one place? ...
2
votes
DB Class extending PDO w/ other useful functions
Much of my advice can be found in https://www.php-fig.org/psr/psr-12/.
The opening curly brace should be on the next line after the declaration.
Method names should be camelCase.
In most cases, I ...
1
vote
first try packagist: Detection of execution by command (Terminal) or web environment
Given you stated "Opinion is understood as everything related to good practices based on PSR/symfony2 code style, security, distribution practice and anything else that comes to mind." I ...
2
votes
PHP routing system
I apologize that nobody has reviewed this code in six years since it was posted. Perhaps you have learned a few things since then but hopefully the review below will still be helpful.
Array syntax
I ...
Top 50 recent answers are included
Related Tags
php × 4345object-oriented × 663
mysql × 583
security × 392
pdo × 328
performance × 307
laravel × 253
mysqli × 244
html × 240
beginner × 236
array × 221
mvc × 214
sql × 194
php5 × 190
javascript × 179
authentication × 160
validation × 129
design-patterns × 125
wordpress × 121
ajax × 113
jquery × 111
form × 109
session × 98
codeigniter × 98
classes × 90