The only correct answer is: benchmark it. If it takes a lot of compute to generate the JSON files, then absolutely, persist the json files. Are the json files stored locally? Is MySQL local? Are you doing 1 query? 10 queries? 1 json? 10 json files? Both solutions are valid, but only a benchmark is going to tell you which is optimal.
For development, warnings like that are a god send. If I were using your class, and there was a slight naming difference between array and class it would be a hard bug to spot w/o a warning. And I might suspect the issue was with the type conversion.
I think you might want to consider making an Interface or Trait so that you can populate private/protected properties.
I'd also issue a warning if the array you are trying to cast as an object has keys that are not existing object properties, because the data is silently lost in the conversion.
My company is also on Yii 1.1, though we haven't really discussed migrating. I would say that the main business case is that as the php version increases, there are going to be more and more BC breaks. I am not sure how actively Yii 1.1 is will be maintained, so you may end up being forced to effectively fork Yii and do your own compatibility modifications as time goes on. NTM that you're missing out on a lot of the benefits of more modern code.
IMO the difference between a "junior/intermediate" and "senior" developer is more about mindset and approach. A junior is more likely to be aware of/think less about the edge cases, and ramifications of a problem/solution. Seniors tend to need to look at things from a bigger picture perspective, and how any given change will affect the overall system.
The job of a senior dev is to build the foundational elements that the intermediates and juniors will extend upon. You don't need to know specific technologies, those change too frequently, what you need to know is how to identify what a system needs. Is it slow? Is it unreliable? Is it hard to develop in? And then, what kinds of things can fix that, caching? Better database design? A more developer-friendly framework? And so on.
Easier how? And actually, the answer I determined while trying to find a "channel webhook" is there is no difference.
If you had to post to 15 different channels, with your library, I'd need to create 15 webooks, and then pass them all in the constructor with the channel name as the key. VS creating 1 hook, and being able to specify any channel.
So it's a bit of a matter of perspective. Also, being able to dynamically name the sender (and an icon) is very useful.
So this is using the Channel webhook/API? As opposed to the App API/Webhook? Internally we use the App one because you don't have the constraint of 1 hook/channel. Is there a benefit to using the channel hook over the app hook?
With the app hook it can specify display name, channel, icon, and attachments along with the text. I don't know the internals of the Guzzle client well enough, but if the array passed to 'json' in the post function contain non-utf-8 characters, does it handle them? Does it just blow up? Does it send out an empty json?
I'm visually impaired, so the main issues for me are text that is hard to read for reasons like contrast, size or text showing up and then going away before I have a chance to zoom in to read it.
When it comes to websites, "responsive" sites can be painful, because even on a large monitor, if I have to zoom 2-3x to embiggen the fonts, often the site will just rescale and hide elements instead of filling the window.
Apps/sites also not letting you highlight text is also a major annoyance.
You seem a little defensive, just trying to give you some constructive feedback.
So first, the verify methods, I didn't see your dev branch before I wrote the comment, so there was no caching. You are using the verify methods in query building methods. If you're allowing user input to determine column names without external validation, you've got other problems. If you're worried about injection, a simple string validation is going to be be much faster. Also, if you're in a multi-database environment, your SHOW TABLES method won't work. (select ... from db1.table1).
Calling the same "prepared query" 10x is much slower than calling 1 extended insert of 10 rows. And if you want to build an extended insert, it's better to build it out with quoted values.
the point of the multi method is to prepare the query once and execute each set of data using the same prepared query. This prevents an extra database call for each data set.
It doesn't work that way. It might save a "create template' cycle, but it's still running the query N times.
The multi method doesn't make a lot of sense to me, since it will only return the last result.
$pdo = new GrumpyPDO();
$sql = "SELECT id, name FROM people WHERE id = :id";
$users = $pdp->all( $sql, [['id' => 1], ['id' => 2], ]);
print\_r($users);
// result
// Array(
// 'id' => 2,
// 'name' => 'John',
// );
Quoting is preferred (IMO) in larger queries. If you're sending >10 params to a prepared query, or if you're using non-named placeholders ( ? ) it can be hard to debug.
As for my last comment about an internal method I would catch the native PDO Exception, and then put some more verbose debugging like the query that was executed, and the data that was sent. And probably some environment checks for more or less debugging whether you are in a live or staging environment.
In my codebase I have a specific class that builds insert queries, the signature is:
Doing that with a prepared statement for dozens or hundreds of rows would lead to some really ugly queries, and doing them 1 at a time would be very slow.
Your insert method doesn't actually support multi-inserts, though I see it is detected, and then you only insert the first row.
You don't have support for the ON DUPLICATE KEY syntax. Or support for functions in inserts (time based functions, etc).
I honestly wouldn't bother with the whole "verify table" thing. Much better to just throw Exceptions on failed query attempts. You're doing at least 2 extra queries for every query you do. Better to run the query, and then try and give good debugging.
I am not sure I understand the logic behind the multi method? It will only return the last executed statement, and doing queries in a loop is generally not reccommended.
As much as I think prepared queries are great, there are situations where simply using pdo::quote is preferred, and since you extend pdo, it's still available, but I'd probably add a way to do a whole array at once.
And since in some cases you are building the query, it can be useful to put all the queries through a private method with extra exception handling and debugging.
If PHP had stronger types, I could see a "__toInt()" method, but because of the vagueness of types you'd have to trust php to pick the right type to cast to to invoke your method.
Where OOP shines is being able to have shared behvaiours amongst a series of things.
So if you had a 5 page website, you could have a AbstractPage object with an abstract display function, and then Home, About, etc.. extend the Abstract class and implement the display function. So then when a request comes in you say "(new $pageClass()->display())" or in a more complex way
I can't tell if this is the log in or sign up page. The lighter "Sign In" makes me think it's to sign in, but the inputs are clearly for sign up.
The button should be labelled with the action to reinforce the action that you are about to take.
Having the user and email icons is good for people who don't bother to read, but (I assume) the eye in the password is to show the password text, which is confusing, since the first 2 are hints, and the 3rd is an action.
I also don't know the purpose of your application, but is it necessary to have a username on top of an email address as a unique identiier?
Not really clear why Ga is an alt color in the top and bottom. I don't get the "holding a controller" vibe from any of them. Having a d-pad in the middle of the middle logo enforces the "video game" vibe in a subtle way.
integer xdebug.show_exception_trace = 0 #
When this setting is set to 1, Xdebug will show a stack trace whenever an Exception or Error is raised - even if this Exception or Error is actually caught.
So looks like xdebug will do that for you. Though I would suggest not having that on in production.
I'm sorry, but this video is painful. It's almost 2020, there is a builtin function for getting the first key as of 7.3 and the documentation has a suggested polyfill. Get the key, reference the key in the normal way ($array[$key]). Or just write a polyfill for array_first_value( ) and do the same foreach..return $value. Most of the suggested methods modify either the array pointer or the array itself ( reset, array_shift ) or involved creating a modified copy ( array_values ).
Also the presentation of a music bed over a command line terminal, where 90% of the screen is just black) with no explanation as to when applying way x vs way y would be good, is unwatcheable. And probably is just going to confuse "beginners" more than a 30 second sound clip.
lol from 2023
The only correct answer is: benchmark it. If it takes a lot of compute to generate the JSON files, then absolutely, persist the json files. Are the json files stored locally? Is MySQL local? Are you doing 1 query? 10 queries? 1 json? 10 json files? Both solutions are valid, but only a benchmark is going to tell you which is optimal.
Jesus on a cross maybe?
For development, warnings like that are a god send. If I were using your class, and there was a slight naming difference between array and class it would be a hard bug to spot w/o a warning. And I might suspect the issue was with the type conversion.
I think you might want to consider making an
InterfaceorTraitso that you can populate private/protected properties.I'd also issue a warning if the array you are trying to cast as an object has keys that are not existing object properties, because the data is silently lost in the conversion.
My company is also on Yii 1.1, though we haven't really discussed migrating. I would say that the main business case is that as the php version increases, there are going to be more and more BC breaks. I am not sure how actively Yii 1.1 is will be maintained, so you may end up being forced to effectively fork Yii and do your own compatibility modifications as time goes on. NTM that you're missing out on a lot of the benefits of more modern code.
IMO the difference between a "junior/intermediate" and "senior" developer is more about mindset and approach. A junior is more likely to be aware of/think less about the edge cases, and ramifications of a problem/solution. Seniors tend to need to look at things from a bigger picture perspective, and how any given change will affect the overall system.
The job of a senior dev is to build the foundational elements that the intermediates and juniors will extend upon. You don't need to know specific technologies, those change too frequently, what you need to know is how to identify what a system needs. Is it slow? Is it unreliable? Is it hard to develop in? And then, what kinds of things can fix that, caching? Better database design? A more developer-friendly framework? And so on.
array_reduce might work? Something like:
3v4l example. I changed the idcaracteristica of the 3rd and 4th elements so it would be 2 queries.
Easier how? And actually, the answer I determined while trying to find a "channel webhook" is there is no difference.
If you had to post to 15 different channels, with your library, I'd need to create 15 webooks, and then pass them all in the constructor with the channel name as the key. VS creating 1 hook, and being able to specify any channel.
So it's a bit of a matter of perspective. Also, being able to dynamically name the sender (and an icon) is very useful.
So this is using the Channel webhook/API? As opposed to the App API/Webhook? Internally we use the App one because you don't have the constraint of 1 hook/channel. Is there a benefit to using the channel hook over the app hook?
With the app hook it can specify display name, channel, icon, and attachments along with the text. I don't know the internals of the Guzzle client well enough, but if the array passed to 'json' in the post function contain non-utf-8 characters, does it handle them? Does it just blow up? Does it send out an empty json?
Anyway, cool library.
I'm visually impaired, so the main issues for me are text that is hard to read for reasons like contrast, size or text showing up and then going away before I have a chance to zoom in to read it.
When it comes to websites, "responsive" sites can be painful, because even on a large monitor, if I have to zoom 2-3x to embiggen the fonts, often the site will just rescale and hide elements instead of filling the window.
Apps/sites also not letting you highlight text is also a major annoyance.
You seem a little defensive, just trying to give you some constructive feedback.
So first, the verify methods, I didn't see your dev branch before I wrote the comment, so there was no caching. You are using the verify methods in query building methods. If you're allowing user input to determine column names without external validation, you've got other problems. If you're worried about injection, a simple string validation is going to be be much faster. Also, if you're in a multi-database environment, your SHOW TABLES method won't work. (select ... from db1.table1).
Calling the same "prepared query" 10x is much slower than calling 1 extended insert of 10 rows. And if you want to build an extended insert, it's better to build it out with quoted values.
It doesn't work that way. It might save a "create template' cycle, but it's still running the query N times.
The multi method doesn't make a lot of sense to me, since it will only return the last result.
Quoting is preferred (IMO) in larger queries. If you're sending >10 params to a prepared query, or if you're using non-named placeholders ( ? ) it can be hard to debug.
As for my last comment about an internal method I would catch the native PDO Exception, and then put some more verbose debugging like the query that was executed, and the data that was sent. And probably some environment checks for more or less debugging whether you are in a live or staging environment.
In my codebase I have a specific class that builds insert queries, the signature is:
This builds and executes:
Doing that with a prepared statement for dozens or hundreds of rows would lead to some really ugly queries, and doing them 1 at a time would be very slow.
Quick thoughts:
ON DUPLICATE KEYsyntax. Or support for functions in inserts (time based functions, etc).multimethod? It will only return the last executed statement, and doing queries in a loop is generally not reccommended.Good luck!
Isn't that what interfaces and/or traits are for? Like ArrayObject, Serializeable, JsonSerializable, etc.
If PHP had stronger types, I could see a "
__toInt()" method, but because of the vagueness of types you'd have to trust php to pick the right type to cast to to invoke your method.As others have said, it's probably your queries. I'd probably build a logging class to see:
a) what queries are run
b) how long each query took
c) if the same query is run >1x.
Then figure out why the slower queries are slow, or if queries are run >1x if/how they can be cached.
Also, if queries can be consolidated, are you doing some kind of
selectquery in a loop, could that be done with a join, etc.Where OOP shines is being able to have shared behvaiours amongst a series of things.
So if you had a 5 page website, you could have a AbstractPage object with an abstract display function, and then Home, About, etc..
extendthe Abstract class and implement the display function. So then when a request comes in you say "(new $pageClass()->display())" or in a more complex wayLooking into namespaces and autoloading (specifically PSR-4) means you can compartmentalize things a lot.
I would (in general) avoid using Traits as they sidestep the whole inheritance thing.
Also, PDO is a lot nicer to use (IMO) than mysqli.
I don't understand how people are so effusive about these logos...
mcdonalds looks like a Tennis brand.
apple is basically just there old logo, but not an apple.
Coca-Cola is so-so
The Netflix logo I like, except, it's too tall and the F should be up, not down
Chupa Chups looks like Thupa Thups
ADIDAS is ok, but might be too much emphasis on German colors for a brand that will be on international sports teams uniforms.
The Honda logo wouldn't work on a car, and the red rounded rectangle is too Nintendo.
Ikea looks like a knock-off Pan-Am logo, and looks like an airline, not a home decor shop.
And the Photoshop logo looks like a recolored version of an old Kodak logo.
IDK, they don't really feel very well thought out IMO.
I can't tell if this is the log in or sign up page. The lighter "Sign In" makes me think it's to sign in, but the inputs are clearly for sign up.
The button should be labelled with the action to reinforce the action that you are about to take.
Having the user and email icons is good for people who don't bother to read, but (I assume) the eye in the password is to show the password text, which is confusing, since the first 2 are hints, and the 3rd is an action.
I also don't know the purpose of your application, but is it necessary to have a username on top of an email address as a unique identiier?
Not really clear why Ga is an alt color in the top and bottom. I don't get the "holding a controller" vibe from any of them. Having a d-pad in the middle of the middle logo enforces the "video game" vibe in a subtle way.
So looks like xdebug will do that for you. Though I would suggest not having that on in production.
No. The simplest way I can think of would be something along the lines of having an exception handler class, like this:
Sounds like you want a backtrace. Which you can get with
debug_print_backtrace()and associated methods or xdebug.Are you
throwing the exceptions or are they 3rd party exceptions? Do you only want to know when they are caught? What is your goal?Are you using Apache? Can you give an example of what you mean?
This will make
/api/*directly access the files in that dir. The second rule will then push all requests through/router.phpBTW you should use /r/phphelp
I'm sorry, but this video is painful. It's almost 2020, there is a builtin function for getting the first key as of 7.3 and the documentation has a suggested polyfill. Get the key, reference the key in the normal way (
$array[$key]). Or just write a polyfill forarray_first_value( )and do the sameforeach..return $value. Most of the suggested methods modify either the array pointer or the array itself ( reset, array_shift ) or involved creating a modified copy ( array_values ).Also the presentation of a music bed over a command line terminal, where 90% of the screen is just black) with no explanation as to when applying way x vs way y would be good, is unwatcheable. And probably is just going to confuse "beginners" more than a 30 second sound clip.