PHP

Support group for those afflicted with PHP. Don't ask to ask, ...
Jun 24, 2023 12:42
@Danack I was asking how things have changed. Thanks, I found my way already. I liked how things were though. :) But it's just me living in 2013 still
Jun 24, 2023 12:40
Oh, cool, thanks I was reading old internals book it seems.
Jun 24, 2023 12:38
Just curious why were these definitions removed from the headers?
Jun 24, 2023 12:37
Hey. I was trying to port my old implementation for adding Url class to the standard library (fun weekend project, I am not even gonna bother with RFC) :) I see that internals have been changed drastically. Can anyone help me find where/how function/module definition should be done for these? github.com/leri/php-src/blob/php-src-url/ext/standard/url.h Thank you so much
Jun 23, 2023 17:44
This is a very high-level idea. Obviously, I know that php does not have AST at runtime, however, I think it's doable with some tweaking
Jun 23, 2023 17:43
Find function received a class of expression that gives access to the AST of the anon function giving you control to translate the return $user->firstname === $passedInUserName; to where u.firstname = @username)
Jun 23, 2023 17:42
E.g. $users->find(function(User $user) use($passedInUsername) { return $user->firstname === $passedInUserName; })
Jun 23, 2023 17:40
Me being a C# dev, I mean the same as they are in C# (from functional standpoint). So basically it's very similar to anonymous function you pass in as an argument, however, instead of evaluating it and calling as a function, you get an AST of the passed in function giving you a nice way to transform it into SQL.
Jun 23, 2023 17:37
That's cool. I hope for the better. It was getting pretty descent. Has expressions been introduced? I used to mentioned that they will be very useful especially for ORMs.
Jun 23, 2023 17:30
Cool. I have not done php since 5.6. :) I can't wait to see how much the language has evolved.
Jun 23, 2023 17:27
Hi. It's been ages since I logged in here. This chat used to be so much active.
Apr 18, 2022 18:17
Thanks, that makes sense. In 2014 I wanted to make a RFC for the same but caught up with a lot of work. Wanted to get back to it just for fun. Here's the initial idea if anyone is interested: github.com/leri/php-src/commit/…
Apr 18, 2022 18:08
@AllenJB PHP already offers functional way to work with urls at the core (unless I am missing something and these functions got deprecated). From my old days with PHP almost every project had its own implementation of url. So, basically, the idea is to make programming API uniform and not scattered all over the place.
Apr 18, 2022 17:56
Good evening, folks. I was just wondering if there's any plan to add \Url class in php? If no would you like to see it?
Nov 28, 2021 14:25
@JRL While it might be unnecessary it would open room for lots of things so custom casting would be very useful for different purposes. If I get enough motivation, I may give it a try
Nov 28, 2021 12:45
@JRL Unless we fix/normalize the implicit casting your mission will be very hard. Why won't we take from there?
Nov 28, 2021 12:06
Thanks, you too. I will still come by from time to time. :)
Nov 28, 2021 12:05
Well, more I look into the php as of now I am getting more and more disappointed to be honest. I have quite large pretty descent framework with routing, DI, ORM, etc. but probably I will just rewrite it into some other language... The language is clearly falling behind and that's sad as php is my first language.
Nov 28, 2021 12:00
@JRL interface Convertible { function toInteger(): int; function toBoolean(): bool;... }
Nov 28, 2021 11:58
Also Comparable interface rather than compareTo method have getHashCode which would represent the object in int
Nov 28, 2021 11:57
Hmm, why cannot we introduce cast if object implements specific interface? e.g. Convertible?
Nov 28, 2021 11:50
Hmm, I see. that's kinda messed up though. :| In an ideal world I would be able to do function sort(CollectionOfComparables $comparablesArray). I guess that would be impossible based on current implementation
Nov 28, 2021 11:43
While with magic functions you have to dig in if magic function is defined or not
Nov 28, 2021 11:43
@JRL You can simply use if ($obj instanceof Comparable) { // do stuff }
Nov 28, 2021 11:42
Which is pretty clean but obviously can be made even cleaner by passing concrete comparer providers
Nov 28, 2021 11:41
This is what I came up within 2 minutes.
Nov 28, 2021 11:41
Nov 28, 2021 10:12
@JRL Yup, that's actually a problem in my opinion. If we think in OOP what if the object in a state when it cannot be compared? Temperature is a good example, let's say you are trying to compare to a temperature which is below absolute zero (ideally, you should throw an exception at this point).
Nov 28, 2021 10:11
interface Comparable { function compareTo($other): int; }
Nov 28, 2021 10:10
compareTo($other): int and on top of that throws exception if comparison is unsupported
Nov 28, 2021 10:08
@JRL Why not just let the implementation handle that? i.e. if (!($other instanceof Decimal)) throw new UnsupportedComparison ?\
Nov 28, 2021 10:04
Okay, makes sense regarding notequals, but how is interface any different from magic function? I mean in terms of userland code?
Nov 28, 2021 10:01
if $comparableObject is null or instance of object which does not implement Comparable interface should throw an exception.
Nov 28, 2021 10:01
@JRL That's actually good one. I would say few points are missing, e.g. if you overload __equals you must force to overload __notEquals, etc. you get my point. However, I was always against having magic functions so introducing interfaces like Equatable, Comparable, etc. would solve that problem. Later on if you do $comparableObject > $otherObject would ideally translate to $comparableObject->compareTo($otherObject) > 0;
Nov 28, 2021 09:53
@JRL I got what you are trying to solve. My question was why do we need to expose it to the userland? I am probably missing important piece of internal working however, as of now I am speaking purely from clean API standpoint
Nov 28, 2021 09:41
I guess so. Anyways.. sad to say but for my liking php still lacks lots of things. :/ Sorry to bother you guys.
Nov 28, 2021 09:35
@JRL Which is absolutely fine. If you have compare function fn(Decimal $d, Fraction $f) => $d - $f will be fired when Decimal > Fraction is invoked and the function fn(Fraction $f, Decimal $d) => $f - $d when Fraction > Decimal. I.e. left operand means comparison function left argument, right operand right one. The only problem that may arise is ambiguity however, that can be handled in a different way
Nov 28, 2021 08:35
Yup, I may be missing a larger picture here but as of now it seems like reinventing a wheel. :)
Nov 28, 2021 08:33
@JRL Just a thought why not just implement comparers? I.e. have the function that takes in two elements and returns subtraction value or throw an error if incomparable items are passed in?
Nov 28, 2021 08:26
@JRL Would not it be wiser to do type check first and then perform an action? Also it would lead to less bugs if stdClass < DateTime triggered a warning or notice, is not it?
Nov 28, 2021 08:16
I just found my old implementation of it and was wondering if it's worth investing time to port it to the new version and make a PR: github.com/leri/php-src/commit/…
Nov 28, 2021 08:14
@MarkR I meant at the language level. I know there are few hundred of custom url implementions out there :)
Nov 28, 2021 08:13
I was going through the docs and can't seem to find Url/Uri class. Has not it been introduced yet?
Nov 28, 2021 08:00
Thanks
Nov 28, 2021 07:59
Hmm, interesting.
Nov 28, 2021 07:57
Morning. What is the best way to implement web sockets with php? How does the lifecycle works for the language where events don't exist and scope it bound to request/response cycle?
Nov 27, 2021 19:45
This is just very raw example how I imagine ClosureExpression. This just an idea so the usage would be more clear.
Nov 27, 2021 19:44
function where(ClosureExpression $expr) { if ($expr->getNodeCount() !== 1 && $expr->getNodeType() !== ClosureExpressionNodeType::MemberAccess) { throw new \Exception("Only member accessing closures are allowed"); } return $expr->getNode(0)->getReturnedMember()->getName(); }
Nov 27, 2021 19:38
@Danack Correct me if I am wrong but technically we could cache AST for closures similarly we can cache OP codes. That would mean minimal overhead. Or we could introduce ClosureExpression extends Closure class which will have all the exposed methods we need to get closure expression tree. This way we don't drag the entire AST but we have reasonable way to see what members are getting accessed
Nov 27, 2021 19:32
@Crell Yes, I totally agree. I was actually rewriting/upgrading my old php framework and figured out we don't yet have AST that's why raised this topic anyways.