« first day (3503 days earlier)      last day (1442 days later) » 
00:00 - 17:0017:00 - 00:00

12:14 AM
@bwoebi That's a .... lot of recurrences though!
 
 
6 hours later…
6:15 AM
Git mergin'.
 
cmb
7:10 AM
@LeviMorrison The test suite runs single-threaded. ;)
 
7:48 AM
The dl() check is just a one-off test to make sure it doesn't crash
As we don't have ordinary tests for dl()
 
 
2 hours later…
9:30 AM
Morning
 
10:02 AM
yawn
 
@bwoebi at least to some extent, this is personal preference, and green is clearly a superior colour to help the bikeshed blend into the surroundings. But my own preferences are driven by: I define types, so typedef sounds natural. But more importantly, it is easier to help a junior by using a different word than type.
> Me: Okay, we need to define the callable we're going to use here, so that's 'typedef reducer'
Junior: *types "typedef reducer" on keyboard.
Me: cool...
vs
> Me: Okay, we need to define the callable we're going to use here, so that's 'type reducer'
Junior: *types "reducer" on keyboard.
Me: ah, no - when I say "type reducer", I mean type the two words "type reducer".
I'll put the inline callables back in....can you give me an example of it, that doesn't involve the 'mixed' type. I want to say some words about why the two of them have different patterns of use, so that people can understand why they are both useful.
The 'dropping names from parameters' would need to be a separate RFC that addressed it fully. i.e. if names could be dropped here, why not in interfaces also? /cc @IluTov
 
10:20 AM
@DaveRandom is there any reasonable comparison of LINQ to PDO prepared statement emulation?
In theory, LINQ can change between databases only by changing a conf file, no changes needed to code, I'm wondering how accurate that statement is in practice, and if there's any comparison to PDO's emulation of MySQL prepared statements... but it has me thinking it's another reason to switch to native preparation
 
PDO and LINQ are unrelated
PDO doesn't provide anything related to the way you write your queries/how the queries are abstracted
 
@PeeHaa was this the reason you didn't follow through with the RFC? :P chat.stackoverflow.com/transcript/message/43045183#43045183
 
No. Priorities and real life
 
Cool, when I found your message, I started feeling hesitation on proceeding, but that makes me feel better
 
10:36 AM
AFAIR it's just a matter of changing the default and fixing the tests
Don't think it's an overly complicated fix
Just a lot of work because of the tests
 
On the surface, yes...
 
What else could it be?
I mean it's already a functioning thing that exists
Am I missing something?
 
I'm trying to ensure the chances of it being accepted by going through any potential hurdles
 
WHat hurdles?
What are the issues people complain about?
 
Sec, I need to switch to PC
my bed was comfy and warm :P
I received considerable push back from @Leigh when I brought it up to him, his concerns of it "breaking" prepared statements for users because it may affect how people's queries currently run if they're unaware emulation is even turned on... they just notice that their queries are running differently on PHP 8
(granted, I think that's what the migration guide is for...)
 
10:46 AM
PHP failed to build with link error ・ *Compile Issues ・ #79612
 
So just people using the same parameter twice?
 
there are still some edge cases that native prepared statements don't support
 
Like what?
 
am I right in thinking that emulated prepares work with multiple queries in one string when the underlying database doesn't?
 
CREATE TABLE t (id int default ?), binding ASC/DESC for ORDER BY, $pdo->prepare('SHUTDOWN');
 
10:48 AM
@IMSoP Really??
That's terrible
 
the last one only matters if it's someone using a script to do sysadmin tasks
 
$pdo->prepare('SHUTDOWN'); should not be prepared
 
I might be wrong, I just have a memory of it
 
And the first just blows up I assume
@IMSoP You might be right
That's scary though. That's a terrible difference
 
I'm using examples I was given by Johannes from email responses, I haven't tested the CREATE TABLE t (id int default ?) yet
one reason for switching to native prepared statements is the results are always strings in emulated prepares, they're not properly typed, which fails in strict mode
 
10:51 AM
If it just blows up I don't really see a problem
I would think the most common use-cases are helped by prepared statement
 
I've been going through previous discussions and pulling out pros and cons into a list
 
@PeeHaa it may just be a side-effect, because the DBMS will accept 'UPDATE Foo SET A=1; SELECT * FROM Foo' as a one-shot query, but not prepare it; so unless PDO explicitly checks for that scenario, it will quietly work
but maybe it does do that check, I'm not sure
 
@IMSoP Ihave a feeling you are just correct :) And it indeed works like that
Another reason why emulating it is just a terrible idea
 
yeah, emulated prepares are pretty horrible
 
another reason for switching to native prepared statements is giving users a "safe default" (I had the person incorrect)
 
10:53 AM
but it will be a big breaking change for some people if they're taking advantage of that loophole
although I guess we're talking defaults, so they can just turn it back on?
 
@IMSoP IMHO yes it might break for some users, but it will help more users
@IMSoP correct
 
yeah, I think I'm in favour as a safe default then
 
@IMSoP yes
 
as with exceptions-by-default
 
Yes
 
10:55 AM
the biggest hurdle I think is making sure people are aware that it could (if RFC passes :P) be changing in the next major version, and that if they ABSOLUTELY WANT emulated preparation, that they have to manually turn it back on
 
Make it sane for the 90% by default
 
I'm out of the loop here, why would you want to use non-emulated prepared statements?
 
@PeeHaa But it can be :D
 
@NikiC because people (a)buse emulation
 
@NikiC inconsistent behavior with other PDO drivers, inconsistent behavior compared to server-side prepares, it gives users a "safe default", it returns properly typed results (emulated prepares only return strings)
those are the "pros" I have listed so far
 
10:59 AM
Okay, from that list returning typed results sounds useful
 
"cons" are extra-round trip can potentially affect performance, and some prepared statements aren't supported server-side
this is for pdo_mysql exclusively, I should note
 
Is returning typed results not possible with emulated prepares?
 
as per Andrea, it always returns a string, gimme a sec, I'll link her reply
 
@Derick ... :P
 
11:02 AM
IMO johannes is just being a pita therewith his "ZOMG EXTRA ROUNDTRIP!?!?!"
If that's problem just turn on emulated prepares
 
Johannes is a pretty reasonable dude 😛 he's been answering my questions
answered an email I sent at 7PM my time, which I assume is like 2AM his time...from his phone...
 
It's just not a strong reason imo
 
true
should I send another email on internals to gauge interest again? I was going to wait until I had drafted the RFC and let discussion occur then, but it seems like it might be better to ask beforehand
 
@NikiC Don't you dare trying to improve emulated prepares :)
 
lol
the reasoning for why PDO came into existence was giving database users a level playing field with the ability to easily switch from one database to another without having to change their code (that much, as it turns out), with comparison to other languages (C# and Java where the examples I was given)
but I'm quoting what was told to me
 
11:06 AM
> with the ability to easily switch from one database to another
hahahahahahahah
HAHAHAHAHAH
WHAHAHAHAHA
Sorry. That was funny
 
that's a reason why prepared emulation was built in, because MySQL server-side didn't support a lot of stuff that other DBs did
but that's different in MySQL 8
 
That has not been the case since mysql 5 or whatever
 
it was still an issue in 5.7-ish, granted, not as bad, but there were still a few cases that server-side didn't support, and has been fixed in 8
 
And I would personally forget about even thinking you can just switch db engines
That's utter nonsense
 
surely we should keep with the MySQL style and add a new method $pdo->real_prepare(...) :P
 
11:08 AM
>.<
 
^ :)
 
that sounds more painful (I think it was sarcasm, I hope it was sarcasm)
 
it was indeed
the "real_" prefix in MySQL driver functions always makes me laugh
 
"Coming Soon... REAL... PREPARES"
that probably sounded funnier in my head
 
@PeeHaa it's true that you can't "just switch", but PDO does a reasonable job at some things, like unifying the syntax for parameter placeholders
 
11:13 AM
Sure. But if anybody tells me the premise was interchangeable database drivers I would point and laugh at their face
 
the face?
 
the face
 
they're more interchangeable than what came before
 
Yes. Not my point though
 
it was a vendor's attempt at chipping away at majority usage
 
11:27 AM
user image
3
@PeeHaa obligatory.
 
@Danack Ok but we'd still need to better define how callable type parameter names interact with named parameters. For example:
function foo(callable($foo): void $callable) {
    $callable(foo: 'Foo');
    $callable(bar: 'Bar');
}

foo(function ($foo) {});
foo(function ($bar) {});
Which one of those works? As in, does the type hint modify the parameter names or is it purely informational?
 
Dunno. That would be part of the named params RFC.
 
Another thing: I'd love it if no return type meant void (but I understand that's inconsistent with function declarations.
 
@PeeHaa Having a similar API does reduce cognitive load on developers though, if it doesn't matter which underlaying DB there is.
 
function foo(callable(int) $callable);
// Same as
function foo(callable(int): void $callable);
Again, I don't know myself if that's a good idea because it's inconsistent.
@Danack Depends on which one is accepted first :P
 
11:31 AM
@Derick Again not my point
I understand that
But saying you can switch databases is a lie
 
oh sure
 
@IluTov I think you misspelt 'null'.
 
@Danack that depends which RFC comes first, surely
(oh, sorry, IluTov already said that)
 
race conditions
 
@Danack My main gripe is the equals sign which irritates me, but well :-D It's just a matter of preference, I won't reject your proposal based on that tiny syntax thing.
@Danack I don't think names should be droppable from interfaces - if you have named params, you can meaningfully access params by their names … but not really for callables.
I never use throwaway names in my interfaces, in callable signatures I put into docblock however I sometimes omit the name
@PeeHaa well… I said the same in this chat :-D
@Danack a lot of callables would profit from generics :-P But imagine a callback from the event loop, function repeat(int $intervalMs, callable(Watcher): ?\Generator $callback)
 
12:03 PM
Morning, mi amigos!
 
Hola o/
 
12:28 PM
o/ hi hi
 
@Danack Lots of closures are actually generic but we can't express that (yet) so we just use mixed.
function map<TIn, TOut>(array<TIn> $array, callable(TIn): TOut $mapper): array<TOut>;
Would be the map example with proper generic types
That's also why I think callable types will become 10x more useful once we have generics.
 
12:51 PM
Man the match RFC sucks, I can't even provide two truly equivalent examples that use echo...
switch ('foo') {
    case 0:
      echo "Oh no!\n";
      break;
}
// vs
echo match ('foo') {
    0 => "Never reached\n",
};
because one only allows statements and one only expressions.
 
cmb
any news about @JoeWatkins?
 
@IluTov Cheat and use print
 
@IluTov in my mind, switch is glorified if+goto, match is glorified nested ternaries; there's no reason they need to be related at all
 
@IMSoP This example demonstrates type coercion, there's no way not to mention switch.
Remember, switch compares some value against a set of other values. This is not the same as an if/elseif/else chain and not the same as nested ternaries. I don't know why everybody thinks match and switch aren't related.
 
they're related, but they're related to lots of things
 
1:01 PM
@NikiC That's a little deceitful but I might just do it :D
 
that doesn't mean they have to be a replacement for each other
 
Well, that's what it was meant to be.
 
@cmb I was wondering why we haven't heard from him in awhile.
 
@IluTov yes, and I and others have been trying to encourage you to leave that intention by the way side
not because it's a bad intention, but because it's orthogonal to what we've ended up with
present match on its own merits, as a way of doing thnigs which we sometimes want to do and don't have a good syntax for
or go back to basics on switch, and propose a "switch strict" which is still statement- rather than expression-based
 
@IMSoP Opt-in security is not a good idea. Writing safe code should be simpler than writing unsafe code.
 
1:09 PM
then make a breaking change to switch
 
@IMSoP You know that's never gonna happen.
 
then it's a moot point; whether you call it match, or switch strict or real_switch, there's thousands of examples out there which people will copy using plain old switch
so they'll have to know to opt in to whatever new version you create
 
The point is that the more secure version should be shorter. I also think omitting a return type should mean void and no visibility modifier should mean private.
Just simpler to write.
 
so call it swit
:P
but if that's the aim, make it the same syntax as switch, or people won't bother learning it
 
Man I always thought implementing an RFC was the hard part :D
 
1:14 PM
Haven't you seen short tags? :P
 
I stand by this e-mail: externals.io/message/109842#109932 - a stricter form of switch doesn't need any new syntax, just a new keyword to introduce it
 
Or the strict ops declare, which is back up for discussion
 
maybe we could have switch strict and switch lax, and make plain switch a deprecated alias for the lax variant
@Girgias that solves one part, but doesn't allow us to tighten up the fallthrough and exhaustiveness behaviour
 
@IMSoP Would your switch strict do that about the fallthrough?
 
see the mail I just linked
 
1:22 PM
Ohter than the reuse of continue which I'm really not a fan of, I'd probably prefer to go the C++ route of introducing a "no-op" fallthrough keyword
But seems fair
 
yeah, the only advantage of re-using continue is avoiding extra keyword reservations
but for a phase one, I'd probably not add anything, just let people say "in this switch statement, I'm not trying to do any fancy fallthroughs, tell me if I do by mistake"
 
I feels that gonna get confusing real fast if you have it within a loop
Sure that can always be left to future scope if it's controversial
 
indeed; "fallthrough" or "nextcase" or something would be clearer
 
@IMSoP It's still more verbose, can't return values and other than that just tries to do the same thing. I think you're just bullying me :(
 
it's trying to do the same thing as switch
 
1:25 PM
So is match
Just better
 
no, it's trying to return values, and uses completely new syntax
I really like it, but even with blocks, re-factoring existing switches to use it would be non-trivial
having control structures usable as expressions is a nice language feature, but we don't have it on any other control structure, so I don't miss it on switch
again, I really like match; I can definitely imagine using it, on its own merits
 
@IMSoP It uses different syntax to be more concise. What's the point of adding verbose syntax just to be more similar?
 
to upgrade current code
I work on a legacy code base, with huge chunks of procedural code in one giant switch statement; those should absolutely be using strict equality and erorring if they accidentally fall through; I want that to be as easy as possible
 
@IMSoP Should legacy code really be the reason new syntax is built in a sub optimal way?
 
yes
 
1:35 PM
I'd imagine PHPStorm would even build a simple fixer where you can convert them back and forth.
@IMSoP I absolutely disagree.
 
but what does it gain me?
 
It's more concise to write and will encourage people to actually use it.
 
is that "concise" syntax actually going to make a difference in a 200-line switch statement?
 
If you use it in all the other cases, chances are you're also going to use it for the 200-line one.
 
we're talking, what, 10 letters saved per branch?
case+:+break; vs =>{ + }
7
 
1:38 PM
Hello :D Im sorry for asking this here, I want to test a project im working on and I want to get a notification in stackoverflow.
Can somebody @Raamyy so i can get a notification ?
 
@Raamyy .
 
@IMSoP Per branch. Which is not insignificant. Were you in favor of arrow functions? You don't save much more there. But it reduces cognitive load.
 
I was on the fence, to be honest
but for single-expression lambdas like we have, the saving is significant enough that I was persuaded
I am not in favour of extending them to allow function bodies
 
@IMSoP I very much am
Mind you it's not for the short syntax it's for closing over the scope
 
yeah, I think that should be orthogonal
use(*) or something
 
1:43 PM
@IMSoP That's still new syntax.
 
I would prefer use(-) is you want to disable it :D
 
@IluTov it's new syntax based on what we have, exactly like I'm arguing for with switch
prioritising consistency over saving a few keystrokes
@PeeHaa well, I guess it's a bit late for that
 
I'm jesting, although it annoys me to no end that our closures don't close over the scope automatically
 
I'm still not totally sold on auto-capture for long closures anyway; my instinct is that trying to capture lots of variables is like trying to accept lots of parameters
PHP's scopes are all explicit, it seems logical that closures are too
unlike in, say JS, where scopes inherit like mad
 
I can see that. However with the amount of closures I write having the import them all is somewhat bonkers
 
1:48 PM
like I say, some concise way to write "this function uses auto-capture", I could get on board with; but tying that to function vs fn feels arbitrary
 
Well it's already the case
fn already does auto capturing vs function
 
I don't think of it that way; I see fn as more "turn this expression into a closure for me"
I know technically that means "auto-capture the variables and add an implicit return, but it feels like a distinct feature
whereas fn($x) => { if ( $y == 0 ) { blah() }; } doesn't immediately feel like a different feature from function($x) { if ( $y == 0 ) { blah() }; }
 
@PeeHaa Wow. I thought we could be friends, but not any more. :P
 
@salathe :-(
 
the conversation gets tangled up because auto-capture makes the syntax shorter, but the actual difference between fn()=>{} and function(){} is pretty minimal
 
1:54 PM
hrm, gh having problems again
 
I couldn't care less about writing function instead of fnpersonally
 
P.S. If I got a penny for every time I've written ($foo) => do_something(), I'd be a tiny bit richer by now. My brain just can't handle the fn. :P
 
Is travis fucked lately too? It didn't build my xdebug PRs yesterday
 
@salathe Same. Switching languages is annoying :)
 
@salathe Bonus pennies if you messed that up within an array of callables
(and thus got no syntax error at first)
 
1:56 PM
ouch!
 
haha
 
@bwoebi :D
 
oops, I should really stop Having Opinions and get on with some work :)
 
I still type out array(...) instead of [...]. Change is hard!
 
@salathe don't worry my php-cs-fixer gitlab pipeline will overwrite that for you
 
1:58 PM
@salathe I don't, and it constantly breaks tests :/
 
Incident on 2020-05-19 14:04 UTC
 
@Sjon 3v4l.org/bughunt/7.4.6/7.4.5+7.4.4 contains a link to a 2nd page, but second page is blank?
 
@bwoebi nice, I'll have a look
 
@Sjon and you probably should also blacklist DateTime with relative dates like in 3v4l.org/2QsR9
(and date() itself)
 
2:13 PM
@bwoebi ah - that's because I'm lazy. I don't actually count how many pages there are. If there are exactly 25 results I assume there are more and only fetch them when the page is actually requested
 
how dare you not properly handling the edge cases :-P
@Sjon you provide a quick eval for git master … but … when is the build from? may you add that info?
 
@bwoebi you are right. That info is shown on the 'branches' tab for a full execution when hovering over the version-number
 
All issues have been resolved!
 
2:27 PM
Hi
 
@bwoebi it's not pretty but I've fixed it
 
I need a help regarding printing of retrieved images in ejs page column wise.Will anybody help me out?
 
@Sjon cool
 
@bwoebi the blacklisting is a whole different story. But that specific script should actually work just fine
 
Will anyone help me in working with ejs
 
2:30 PM
@Sjon I mean blacklisting from bughunt - as not all scripts are going to be run at the exact same second on all versions?
 
@bwoebi I understand - but actually all scripts do run at the exact same second because I fixate the time of execution with a LD_PRELOAD wrapper
 
@Sjon uhm okay, so where does the variantion come from in that particular script?
 
> Don't ask to ask, just ask.
 
@bwoebi most of the time it's caused by variation in startup/execution time but I'm not sure about this one. I'll look into it
 
0
Q: Print retrieved images from database in columns

user14I am retrieving images and name of my recipes from database using node.js.I want my images along with recipes names to be printed in column wise in rows. Here is my js code: var sql ="SELECT rname,image FROM recipes WHERE ringre LIKE '%" +items[0]+"%' "; for( var i=1;i<items.length;i++){ ...

 
2:35 PM
@Sjon I'm curious, what exactly does your LD_PRELOAD wrapper look like?
I mean the overriding function code for gettimeofday() (I assume it's that syscall)
 
@user14 this is a PHP room; I see you've already posted in the JS room; this is borderline spam
 
@bwoebi probably another edge-case as re-executing that script fixes it
 
@IMSoP I am trying to get my issue solved
 
Zoe
@IMSoP Flagging is overkill. Ask a RO to move the message to one of the trash rooms instead (here's one: chat.stackoverflow.com/rooms/23262/trash-can)
 
@Zoe I didn't flag it; I just politely told the user they were being a pain
 
Zoe
2:47 PM
It still got flagged :')
 
@Zoe sry I flagged it - didn't see @IMSoPs message
 
@user14 asking a vague question and spamming it in every chat room you can find is not a good way of solving a problem
3
step 1 is always: Break The Problem Down
 
@Zoe Coming in here for a single flag and pointing it out to the entire room is overkill
 
Zoe
@PeeHaa Not really.
 
It is
As a RO I told you so
 
Zoe
2:50 PM
I still disagree. /shrug
 
@IMSoP ok I won't do it again and remember this
 
3:17 PM
Tests should look for XMLSERVICE in QXMLSERV ・ ibm_db2 ・ #79613
 
I have a table that stores items from a manifest; 3 columns (Auto Increment Primary ID, Shipment Tracking Number, Item Description.) I'm adding the ability for the received items to be rejected by the receiving staff. Wondering if I should just add another column titled rejected(int) with a value of either 1 or 0 indicating whether it was rejected... or add another table and only insert entries that are rejected into that table.
Probably trivial- but interested in the better approach.
 
At minimum I would make rejected a nullable datetime field
For the rest of the question it somewhat depends how much control you want / need
 
@PeeHaa Interesting... that would kill two birds with one column.
 
accepted 1 by default
 
3:29 PM
If I have a class that has no public setter methods (only getters and such) and the data passed into it is the same across the request (this class represents the request itself) is there a reason for me not to make it a singleton?
 
Killing bird when staff doesn't know what they are doing and reject something shouldn't be rejected. @StatikStasis
 
@SessionCookieMonster Yes IMO. Singletons can be abused by hiding the dependency as they are basically just globals
 
@Tpojka It's an e-commerce department. They reject stuff submitted by other stores all of the time. I'm just wanting to track their rejection rates now by store. Hoping the feedback will help stores know what to send and not to send.
 
Like, a bunch of classes in my app are "services" (read- singletons that isolate some functionality in them) - is this bad?
Also, models and such
 
@Tpojka that depends on if the staff have access to the database, or have access to a report that displays the data in a readable format
report|screen|something else
 
3:33 PM
@Tiffany Basically a checkbox on the manifest that will allow them to reject it, which would update the database.
 
@StatikStasis It all ends up to a decision what info is needed eventually
It sucks if you get a question "why was this rejected" and the only thing you see is a flag that it is rejected
Because 99% of the cases some user did something stupid
 
Yeah... I'm thinking I may add a note field for the rejection now... which makes me want to create another table now since I don't want a column of null values for every entry whether it was rejected or not.
 
But it's hard to show them if you don't have any info
 
basically check if column is null, if it is, then the shipment wasn't rejected, however if it isn't null, then display date (or add +1 to a counter to determine rejection percentages)
 
How do I evaluate whether I'm abusing singletons, for example and whether it is better to have a new instance every time?( Given that the functionality would work regardless)
 
3:34 PM
I didn't say have a new instance every time
I was more talking about the technical implementation of a singleton
a.k.a. a magic super global
If you are thinking about having an object in "cache" in keep injecting that instead of creating a new one that would be fine
 
@PeeHaa Can I have global $*; in a function which makes the current function share its scope with the global symtable?
 
@bwoebi Sure you can! In your own fork of PHP! PHB! \o/
 
In my case I'm passing an instance of an object to the context of a chain of responsibility(which could be run several times during a request), so either that would be a new instance every time or a singleton. Since it has no setters the functionality fits regardless.
 
PHB: Hypertext Bob?
 
@Tiffany yes
@PeeHaa pfffft
 
3:38 PM
Personal Home Bob
 
@SessionCookieMonster When you say singleton. Are we talking about a global class with static magic or just a normal object instance which you keep passing into things?
 
@PeeHaa I mean a class with a get_instance method which returns the same instance every time
@PeeHaa I'm passing it into things, yes
 
@SessionCookieMonster Yeah that is disgusting IMO
 
@PeeHaa Please explain
 
That allows people to magically use the class without asking for it (in the constructor)
That's wide open for abuse
 
3:41 PM
But this class only has getter methods
What kind of abuse do you mean?
 
How do you know a specific class is using your singleton?
You need to look into the actual code of the class
 
It hides the fact that the class is used from the interface
 
Which interface?
 
The class that uses the singleton
Do you write tests for your code?
 
3:44 PM
And if the class had a separate instance of the other one how would that be different? Isn't it just filling more memory with the same data?
 
I am not talking about separate instances
10 mins ago, by PeeHaa
I didn't say have a new instance every time
Start from there again ^
My point is that you create a singleton without the magic global stuff
 
the difference is that the class using the object shouldn't know that there's only ever one instance
it should just know that it has an instance
 
That is the case
 
not if you have a getInstance method
 
@StatikStasis Seems reasonable additional table with no checkbox on front but only text field for notice. though db trigger before insert notice to set rejected = 1. You don't need checkbox about something rejected but you need reason which is automatically calculated as item is rejected.
 
3:46 PM
everywhere that calls that knows that it's a singleton
 
then pass down that instance instead of asking for it to the class
 
@IMSoP I don't understand how it is different
 
function doThingsWithFoo() { Foo::getInstance() vs function doThingsWithFoo(Foo $foo) {
 
But at some point I will have to create an instance of Foo to pass it there anyway
 
yes, but the class doesn't care where it comes from
it's the difference between "this recipe requires an egg" and "this recipe will cause an egg to appear"
4
 
3:52 PM
:-)
 
^ Default set can be done with PHP but trigger is more safe. @StatikStasis
 
Even then the code that does things with that class can be triggered an arbitrary ammount of times by code that I have no control over and at that "top layer" I have to get an instance, right?
 
yes, but only at that top layer
which is a layer you can replace, e.g. with testing code
also, what do you mean by "have no control over"?
 
It's a wordpress plugin, the functionality of which can be triggered multiple times during pageload via shortcodes etc
 
OK, either you didn't say that or I missed it; when you're plugging into existing code, architectural decisions are very different
 
3:56 PM
I don't see the relation between the number of times somethings gets triggered and passing an instance to a function/method/constructor
 
Yeah sorry I didnt mention that
 
@SessionCookieMonster WP also has places that get only triggered once AFAIK
Nothing stopping you from just injecting stuff
 
yep, you can still have proper depedency injection, because the plugin can have a setup function that constructs an object, passing in its dependencies, and sets one of its methods as the hook callback
 
So what you're saying that instead of using a singleton pattern I should create the instance only once normally and then pass it around?
 
Yeah
 
3:58 PM
precisely
 
Exactly
 
My question then is why is the other approach bad and whether I should avoid using the singleton pattern entirely then?
 
coding using Singletons (or any other type of global state) is hard to test, and hard to adapt
 
Why have been telling you exactly this the entire time
Please read up
 
When I say "the singleton pattern" I refer to using it with the get_instance function and the private constructor
 
4:00 PM
It makes it harder to test, Singeltons are glorified global state (which is bad)
Do you mean a "named constructor" ?
 
with global state, you can't look at that piece of code on its own, reason about what it does, reuse it in a different context, write tests that only touch that one piece of code, etc
read-only global state is certainly better than mutable global state, but it's still relying on magic happening elsewhere, not listing the ingredients you need for the current task
 
Wes
\o
 
o/
 
@Tpojka The staff actually click on a shipment number in the system and it displays the manifest to them. I was just adding a checkbox to that screen by each item which the staff could check if they are going to reject an item. It would then prompt them for a reason for the rejection which will be a drop down list of reasons and a note field for any additional comments they would like to add about the rejection if needed.
@Ekin Your boyfriend is fired up.
 
story of my life
 
4:13 PM
=D
 
4:24 PM
does anyone happen to know a good tool for scheduling PHP jobs, so you don't have to manage loads of manual cron entries etc?
possibly something kind of like hangfire.io but for PHP
 
@StatikStasis Well, it seems you have way better plan than the first question covered. :D
 
00:00 - 17:0017:00 - 00:00

« first day (3503 days earlier)      last day (1442 days later) »