« first day (2326 days earlier)      last day (2618 days later) » 

5:04 PM
Does PHP do any kind of caching of objects on it's own? If you construct something once, then construct the same exact thing again later, does PHP reconstruct it a second time, or just use the firstly already constructed object, because they're identical objects.
 
they are not identical objects, they are different objects that happen to have same values
 
ok thanks for clarifying that
Which leads me to my next question. Do you think it's a bad idea to store objects in the DB?
 
yes
 
Even with instanceof checks?
 
yes
 
5:08 PM
@MichaelEcklund it's a security risk
 
it’s a mess for starters, but that too :)
 
So I should probably reanalyze my architecture then. I'm going to have lotta duplicated objects with this approach.
 
deserialising PHP objects can cause code execution, their constructors and wakeup methods run, by the time you get to an instanceof check, it's already happened
 
if you need same-ish object a lot then reuse a single instance and make it immutable, so that you don't screw it up over runtime
 
I've been trying to not use the WP way and global stuff everywhere.
 
5:10 PM
1: avoid storing serialised data
2: if you must store serialised data, use json
3: Never search or query for serialised data
4: what Rarst said
 
who said anything about globals? :)
 
I used to create the object once, then global the variable where needed.
 
@MichaelEcklund why are you storing objects in the DB to begin with? What problem does it solve and what type of objects are you storing
 
you need better place to keep your stuff then, see Dependency Injection Containers and so on
 
or plain old dependency injection
 
5:12 PM
true, but I find that DI container helps keep things in order on WP extension-level
as above, helps with where to keep stuff
 
I've got the object available and ready at a certain event hook. The problem I've been facing is getting it to the functions which need it. I don't want to be passing variables from a() -> b() -> c() -> d(), etc. Just seems messy. My way around it was to make a getter function to retrieve the object. I can get it when needed and not have to pass it from function to function in a chain like approach.
That's why I was storing it in DB, but now I'm having second thoughts
Let me tell you it was so much easier doing it the "WP way". Create the object once, then just global it everywhere.
 
such thinking keeps me in business
 
Trying to keep my plugins isolated in respective namespaces.
 
5:39 PM
but as always thanks for the advice guys. :)
 
 
3 hours later…
8:30 PM
Jess Pardue on February 27, 2017
Welcome to the Stack Overflow Podcast #102 recorded Thursday, February 23, 2017 at the Stack Overflow HQ in NYC. Today's podcast is brought to you by rogue cows and SHA-1. SHA-1: You can depend on it.
 

« first day (2326 days earlier)      last day (2618 days later) »