« first day (4298 days earlier)      last day (668 days later) » 

cmb
8:31 AM
@Trowski Might be more relevant to add it to the changelog (github.com/php/web-php/blob/master/ChangeLog-8.php).
 
9:27 AM
Hello guys can anyone give me a tip on how to handle race conditions in a multi-request situation? For example a user is sending multiple requests to the server with a very low difference of about 0,02 seconds and it appears that on rare occurrences the table field will be updated wrong. I am not sure on how to fix this beside maybe using transactions but I do not understand on how to use transactions if the MySQL queries are across multiple functions/files.
 
9:42 AM
@zbder You start a transaction, you commit a transaction, everything in between is within the transaction. Where those other calls are is largely irrelevant
 
@MarkR But where do i start the transaction? For example i calll game.php and inside that file i call 2 functions from other files like: UpdateBalance() from balance.php and CheckQueue() from queue.php. Do i have to start and commit the transaction in game.php and it affects balance- and queue.php?
 
That's right, your database has no idea where your functions are being called from, all that matters is the order
 
Oh interesting, thank you very much i will try that now.
No sorry i still struggle to understand. So, i call game.php, inside that file i do call some functions like checking open tasks, then i call balance.php which should update the users balance on the end of every request but it does not affect the game.php anymore at that point. What i am uncertain about is: Should i do beginTransaction() in game.php but commit(); on balance.php which is the last function to be called in order to save the balance change performed in this whole php request?
 
10:05 AM
begin_transaction();
onefunction(); // doesnt matter where this is
anotherfunction(); // doesnt matter where this is
end_transaction();
 
And does it matter that begin_transaction and commit_transaction are in the same file or does solely the order of being called matters?
 
just the order, but you should usually call it in the same function as you started it in
your other functions should do their thing and then return to the origional function, which can then end the transaction
 
Hmm the thing, there is no "same function as you started in". t happens like this: Request started -> game.php called -> Check overall tasks and save balance if task done -> call respective function like addOneToBalance() for example -> save balance again - how can i put this in a single transaction or is the structure simply bad?
 
cmb
10:29 AM
Yeah, I suggest to rethink your design.
 
 
1 hour later…
11:40 AM
I am so lost on this topic - if anyone would like to help me fixing this, i would pay 100 euro for that, i really struggle badly with it. My Discord is: zbder#0541
 
 
2 hours later…
1:56 PM
@zbder I'm guessing you have code that is floating free inside game.php and not inside functions? If so, then ....that is probably the source of your confusion. Putting everything inside functions and then having a single entry point to your application (often called a front controller) would probably make it easier for you to think about your code.
 
 
1 hour later…
3:22 PM
https://github.com/php/php-src/pull/9071#pullrequestreview-1046706272
Any other opinions with regard to the types of exceptions thrown? The logic behind what exception to use when is not entirely clear to me (also in userland). e.g. what's the difference in usage for ValueError and InvalidArgumentException.
 
@TimWolla not using the SPL exceptions is probably better than using them.
For this, there should be:
 
cmb
@TimWolla The general idea of Errors is that these are programming errors which (usually) should never be caught. The SPL exception didn't have been designed with that in mind.
 
i) A base RandomException
ii) Specific exceptions that are children of that class.
Re-using exceptions is one of those shortcuts that saves a bit of time, but is 'not good' long term.
 
@cmb The LogicException from SPL is documented to have the same purpose :-D
 
The SPL is kind of insane and not doing anything the same as it, has a high chance of being the right choice.
 
3:32 PM
Makes sense, in this case the RuntimeException actually appears in the (first) RFC and adding another class would also technically burn another name in the \Random namespace. For that specific PR the exceptions I add are wrapped within the existing RuntimeException, though.
Asking more specifically for this one: github.com/php/php-src/pull/9071/…. What do you believe to be the right choice there? If that is ever thrown, then it's a clear programming error.
See also the test, showing that it's wrapped in the existing RuntimeException: github.com/php/php-src/pull/9071/…
And circling back to "base exception": Should that rather be a class or an interface? I've seen both done in userland.
 
I'll have a look later. Need to get something from a shop first...
 
Thanks!
 
4:02 PM
@cmb We had a fun issue with this and a 5.4 compatible framework last week, because it didn't know Throwable existed it just caught exception, thus never executing the cleanup logic for an output buffer it expected to close in catch
 
> a 5.4 compatible framework last week
a strange typo. You wrote 'last week' instead of '5 years ago'.
 
Sadly not
FuelPHP is the bane of my professional existence at the moment. Also imagine the fun we had when we discovered that it's custom autoloader called a static _init method on any class it loaded, which could then throw an error if it wasn't running on a webserver, or didn't have any uploads, or the cache wasn't available... as you might imagine that made static analysis more than a little bit problematic
 
It was a fun alternative to static constructors.
 
> fun
 
@TimWolla Error for programmer errors and Exception for unexpected conditions. Adding a RandomException would be wise IMO.
@MarkR s/my/our
 
4:17 PM
Fair point
 
I remember Fuel being a framework that used static methods and LSB a lot, so I guess such _init things were wanted
 
If it had any more static it'd be a damned van de graaff generator
 
@MarkR To be completely fair, it's probably an order of magnitude worse for you.
 
4:35 PM
@Trowski Then RandomException would need to be an interface? Or did you mean "Error" as in literally the Error class?
 
IMO you should say its "RandomException" in the docs but when it comes time to throw you should select 1 class at random from the list of loaded zend class entry's that implements throwable and throw that instead
7
 
5:09 PM
Fun fact about Albuquerque: the airport was renamed to "sunport" in 1994
 
@TimWolla Literally the Error class (or some subclass thereof if it makes sense) and a class RandomException (or a better name – perhaps RandomGenerationException?)
Is there a reason to further differentiate with additional exception classes?
 
@Trowski One is definitely a programmer error...the other one might not be. Maybe. But there's not that much between them....
 
5:48 PM
@TimWolla Have a novella.
 
 
1 hour later…
6:59 PM
\Error was a category of exceptions introduced in PHP 7.0 originally to ensure that existing PHP 5 codes that catch \Exception are not affected by new exceptions changed from fatal or recoverable fatal errors in the engine wiki.php.net/rfc/engine_exceptions_for_php7 wiki.php.net/rfc/throwable-interface
And the Throwable RFC shows the idea that \Error represents coding problems that should be fixed.
Though not in the RFC itself, Aaron wrote an article at the time explaining that even user-land codes can create or extend \Error to indicate coding errors. trowski.com/2015/06/24/throwable-exceptions-and-errors-in-php7
Then Aaron proposed changing errors to throwing \Error in extensions also, and it's accepted in PHP 7.1. wiki.php.net/rfc/throw_error_in_extensions
As of PHP 8.0, \TypeError, a derivative of \Error, is thrown for type checking in built-in functions wiki.php.net/rfc/consistent_type_errors
Another accepted RFC for PHP 8.0 reclassifying warnings in the engine promoted some warnings to exceptions, and this one also uses \Error as the baseline for indicating programming errors. wiki.php.net/rfc/engine_warnings
Yup, too long
I think there is nothing wrong with the SPL exceptions themselves, but \Error is more often used in php-src these days
There would be less confusion if we decided to use \Error or its descendants for new implementations.
 
> I think there is nothing wrong with the SPL exceptions themselves,
 
@sj-i We did de-facto decide that
(For any error conditions that indicate programmer error)
 
7:15 PM
@Danack I think it's relatively innocent in SPL :D
 
You can safely consider LogicException and it's child-classes to be forbidden by policy in new code
RuntimeException is a bit less clear cut -- a custom exception type may be justified in that case
 
Hmm, RuntimeException may not be just a programming error sometimes
Then let's move \RuntimeException from spl and exorcise it
 
 
2 hours later…
9:11 PM
@sj-i SPL is pile of rotten shit that should be thrown away at the earliest we can reasonably do
 
Seems a kind of abomination :) It's understandable though.
 

« first day (4298 days earlier)      last day (668 days later) »