« first day (4494 days earlier)      last day (439 days later) » 

12:01 AM
@StatikStasis A trumpet. I bet it will be visited. :D
 
@StatikStasis vampire survivors
 
 
14 hours later…
2:31 PM
@bwoebi I might add this in the RFC :p
@IluTov do you have merge rights or not on PHPInternalsBook?
 
@Girgias No
 
Okay, let me merge your PR then
 
Thanks :)
 
3:25 PM
> I have seen too many real world use cases where inheritance with typed constants would solve problems.
doubt.jpg
 
3:43 PM
I'm looking at that rfc for code cleanup, and I'm thinking to myself... is this individual change going to make a huge difference? But voting against feels like a proxy vote for never doing any cleanup or inline-documentation, and that's a really bad idea
 
Probably, that's the type of vote that should be reserved for people who actually commit to php src more than a few times a month....
 
Haven't caught up with the mailing list yet (as that's work time) but the only reason why typed constant even make any sense is that class (and since 8.1 interface) constant aren't actually constants lol as you can overwrite them in a subclass, and thus change their type
For global constants tho it doesn't really matter
Which fun fact you can use this trick to force a child class to define the constant
 
He believes he wants abstract consts:
 
Ah
 
For example, an interface could be:

interface DbTable
{
    public const string TABLE_NAME;
}
Which would then be implemented as:

class UserTable implements DbTable
{
    public const string TABLE_NAME = 'user';
}
 
3:53 PM
ah
 
It still bothers me no end that redefining a constant in global is only a warning.
 
> solve problems.
 
@MarkR Yeah that surprised me too recently
 
I remembered github.com/php/php-src/pull/5265 a while ago but cant remember if I ever got around to RFCing it (no i didn't)
 
I think for 9.0 we need to do again an engine warning RFC, but I feel there is still 2y+ before 9.0 and I've got other semantic changes I want to tackle
 
4:02 PM
Mass notification in 8.3 / 8.4 then another round of bumps to exceptions in 9.0?
 
To some degree yes, one thing is that resources should "behave" like object in emiting TypeErrors so that the conversion from one to the other is less of an issue
 
I'm not sure what you mean in that given that we can't specify resource types as far as I know? I'd have though eliminating the last of the resources in core would have been the fuller solution
 
Using resources as array offsets doesn't throw for example (well it is a warning) but yes converting all resources would be best but we can't really force all extenal extensions to do this (well we could remove support for resources within the engine but that feels like a 10.0 thing :|)
 
10.0 / 2030 is a long time away :|
It might be worth opening a ML discussion to start to build up a list of possible engine warning bumps?
 
please don't yet
 
4:14 PM
nah, I think it should come from you. I've already got enough on my plate on that front lol
 
I want to tackle comparisons first with the intent of adding some warnings that should get promoted, but having a list of all current warnings might be useful lol
 
There was one thing I thought would be beneficial for all warnings / notices / error messages in general which would be giving them an ID code. Psalm's labels, typescripts error ids etc are rather handy for lookups, might be useful long term for docs
 
Meh, maybe? But sounds like a lot of effort for messages that should be clear to convey the information. And I'm not sure having an error code would make user ask less questions
 
@MarkR Or a url to a webpage, which could include examples of how to fix the problem.
 
@Danack Yeah, I really like how psalm and TS do it with things like psalm.dev/docs/running_psalm/issues/InvalidCatch
They don't link to the website directly, but give you a constant identifier that will take you straight to it with a basic search (theoretically)
 
 
3 hours later…
7:43 PM
I know I'm repeating what others have said, but going to reiterate it. I sometimes wish PHP had some kind of variation for structs: a data structure that defines class properties with names and types, optionally with assigned values, that can be consistently used elsewhere. A class suffices, but I find it lackluster in terms of trying to understand what a class is supposed to be...
That is, we use classes for multiple purposes.... and yes, a class will do what I want a struct for... but it may be harder to recognize that I'm intending a class to be a struct
 
8:20 PM
@Girgias please let me know when you decide to work on this, would love to help plan it out, having resource complete gone would be a dream lol
 
8:41 PM
So I asked ChatGPT about my code and it recommended using exceptions etc, i.e. when a value can’t be retrieved from a file, it wants to throw an exception. It also wants to implement the singleton design pattern, but I already make sure that my file only gets called once and doing it here would mean I have to do it in all my other files too, so it all sounds tedious. What do you guys think?
(I mean I already ensure that only one instance exists. I initialize it once in my main class and then pass the instance around to other classes)
 
If the first attempt throws should it actually proceed on to do other things?
 
No, but I’m also confident it won’t because that would mean I have my config not set up
 
I think ChatGPT is quite shite. I mean it can produce sentences that sound sensible, but then they aren't always sane, or cohesive with other things it says.
 
In this case it came up with solutions to other problems I was facing and I certainly liked that it complimented my code
 
Shhhh Danack, do not upset our inevitable overlords
 
8:45 PM
@MarkR May I interest you in my "Butlerian Jihad" news-letter?
 
So should I do all the exception handling that it wants me to do and also implement the singleton design pattern?
 
/I should cut down on my apos-trophe usage...
@Jerm. for the singleton stuff, no. Just creating something once is clearer code than implementing that.
Though it can also be done through a function, not just through the classic "singleton as part of a class" code:
function getAurynInjector()
{
    static $injector = null;
	if ($injector == null) {
		$injector = new \Auryn\Injector();
		// Do initialisation here
	}

    return $injector;
}
 
@Danack it can make a decent rubber duck for people who need to be able to bounce thoughts off interactions to start working
Without having to bother another human being
But it shouldn't be used to write code that ends up actually used... giving an idea of how to start, sure
 
But it’s good at writing code
at least for what I did
 
But if the code is incorrect, and you lack the understanding/experience to know that it's incorrect... it's a problem
 
8:50 PM
Chat GPT - Confidently Incorrect
 
Should I do the exception handling it wants me to do all the time?
 
are you opening the file(s) multiple times?
 
also throwing exceptions
No, only once
 
Then you should only open it once most likely, do the checking there, then pass it around if needed.
 
Sorry, so I should not do stuff like that all all the time?
if (!file_exists($filePath)) {
throw new Exception(sprintf('File "%s" not found.', $filePath));
}
 
8:54 PM
You should throw on failure. Try opening the file, if it fails, then throw.
Don't rely on checking things beforehand because you may not catch every possibility, maybe the file exists, but isn't readable for example
 
So for things that can fail I should throw/handle exceptions?
 
@Jerm. to be clear, it's good at offering suggestions on how to improve your code in ways that seem reasonable to you. It's effectively filling the role of a code reviewer, in this scenario. Whether or not it's actually good as a code reviewer, is to be determined.
 
Typically yes.
Exceptions are one means of communicating errors, they tend to be quite reliable at doing so as you can't passively ignore them
 
@Tiffany sure. I can only say that I really like the suggestions it gives
@MarkR do uncatched exceptions end/crash my code?
 
Yes
 
8:58 PM
so as for the code above, if i wanted to continue even if the file wasnt found, I would have to catch the exception
okay, thanks!
 
That's right.
 
In the code base I worked in last, exceptions were used as error messages to the client/frontend
Sometimes the error messages were rendered with their message contents to the end-user, other times, the front-end read the exception and turned it into something else...
They crashed execution though
Also if you want to keep track of an error without notifying the user... use a logger and log messages
 
Exceptions should generally be domain specific, and code higher up the stack should only ever catch exceptions it expects, except for in the case of finally or releasing resources.
You can 'chain' exceptions by catching one type and re-throwing it as another type for a different domain, for example let's say your database throws a duplicate key exception when you try to create a user that has the same email, you would catch that exception and re-throw it as a Http exception with a meaningful error message. Using \Exception is almost always a bad idea Jerm.
There's one exception to catching things you don't know and not rethrowing, and that's your top level exception handler, i.e. the bit which catches things that nothing else catches.
I'm actually giving this talk on Monday for my trainees lol
 

« first day (4494 days earlier)      last day (439 days later) »