« first day (3999 days earlier)      last day (931 days later) » 

12:11 AM
not in this game, but when I played it few years ago I build a pretty big orbital base
 
12:32 AM
@PeeHaa witcher-hmm.gif
 
 
8 hours later…
8:33 AM
How can I serialize object with ignore on certain properties which in fact are services that should not be serialized?
 
9:02 AM
public function __serialize(): array {
    unset($this->foo);
    return (array) $this;
}
nvm, got it
 
9:41 AM
you should probably do

public function __serialize(): array {
return ['a' => $this->a, 'b' => $this->b];
}

or

public function __serialize(): array {
$res = (array) $this;
unset($res['foo']);
return $res;
}

to ensure that you don't break anything before/after serialization :)
 
10:16 AM
Marco trying to teach us about Haskell
 
10:30 AM
@OlleHärstedt what have I missed?
 
11:14 AM
Blog post and reddit thread
 
@OlleHärstedt ah that Marco, when we talk about Marco without full name in this chat we mean the Pivetta one :-D
 
11:34 AM
Oh, who's that?
Ooooh
I actually thought it was Pivetta
Because Haskell
TIL
 
12:02 PM
There are probably other Olles who are PHP programmers/enthusiasts :P
Even other Tiffanys! ... I hope
 
12:15 PM
@Derick found the issue curl was created with extension .bak under /usr/bin/curl.bak renamed it to /usr/bin/curl and it sorted it.I dont understand how or why it saved itself as .bak though.
 
@Tiffany first of all, how dare you
 
12:32 PM
@OlleHärstedt :P
 
1:13 PM
Morning!
 
cmb
1:28 PM
@ramsey, please have a look at github.com/php/pecl-php-uploadprogress/pull/9 (seems to be an important fix)
 
1:42 PM
Hi all
is there any way by which we can write object into file?
 
By serialising it and saving the output to a file?
 
but then I will have to unserialize it to read it, right?
 
Well yes
You can't save an instance otherwise
 
that is the goal actually, save the object as a string in the file
 
2:06 PM
... that's literally what serialisation is about
 
Can serialize it through JSON via json_encode/json_decode
But then you have to work with JSON
 
It only does stdClass "objects" though - you need serialization for other classes.
 
cmb
actually, all public properties are serialized (and there is JsonSerializable)
 
Sure, but you lose the class information with normal json_encode/decode
 
ah, didn't know that
 
2:49 PM
@Tiffany At first glance that sure looks like a game for me
 
3:22 PM
@PeeHaa Kerbal... I've got to learn when to just give up on a mission.
The answer does not seem to always be "more power/more rockets." //cc @Derick
 
Why do class_parents() and class_implements() return associative arrays?
 
@StatikStasis It often means "lighter rockets", though.
Which mission are you trying to do?
 
Let me remember...
Test the flea rocket between 32k and 37k at a specific speed.
 
@Crell Not sure I understand your question, but it's because they can return multiple values. 3v4l.org/iv1u5
Or are you asking why associative rather than list arrays
 
The latter.
 
3:25 PM
Test the LV-T45 Swivel rocket between 30 something k and 37k with a specific speed.
 
Why ['foo' => 'foo'] instead of just ['foo']
 
so that you know which one is the parent of which
ohh no, wait
I have no idea
 
Oh good, it's not just me. :-)
 
I usually get the altitude and I am trying to get the speed and end up over shooting the altitude range before the speed is there. My trajectory has to be more flat- I'm climbing too fast.
Sometimes I feel like I even try to rocket down and I still climb.
 
cmb
@Crell I guess it's sometimes useful to do a lookup on these arrays.
 
3:30 PM
@StatikStasis Which speed? :-) I see if I can whip that up in a Twitch stream.
 
Hrm. I suppose isset($a['foo']) is faster than in_array('foo', $a, true)?
 
cmb
yes, way faster
 
OK, that makes some sense, then.
 
cmb
instanceof is even faster, I think
 
3:34 PM
 
I think it was meant to be a set, rather than a list. 3v4l.org/ZkvR6 It makes sense for interfaces, but why class_parents?
 
@Derick Here is the other one... I've not watched this video so maybe this will provide some assistance. youtube.com/watch?v=4qPq5RjXv44
 
So it's an internal optimization that's exposed kinda because?
 
@Derick Oh you're live! Awesome
 
3:36 PM
yes
probably
it's PHP, it doesn't have to make sense
4
 
OH...
 
@Derick Did you have the speed qualifications met?
 
@StatikStasis It's so hard to not go bonkers in weight
 
3:52 PM
lol, that's some sweet spinning around @Derick
 
I have this $aCategoryNames[] = $this->lookupCategory((int)$sID) ?: ''; where lookupCategory can return false if a category name doesn't exist for a corresponding ID, but I don't want to assign '' to the array... I'd rather just...ignore it, but doing an array_filter on the array after feels sloppy, but I'm not sure of a better way. The lookupCategory method does return array_key_exists($nID, $kCategories) ? $kCategories[$nID] : false;
 
you could loop over the ids, and only assign if the lookup category returns?
 
@Derick Why no chat field in Twitch stream?
 
yeah, wasn't sure if there was a one-liner way of doing it, but that's probably what I'm going to resort to
 
I have strictly no comprehension of one-liner attractiveness :)
 
3:59 PM
I have to map a bunch of values to an associative array, using one-liners is convenient in that process, but I'm not sure of the cleanliness of my code...
also I have to call this lookup method twice XD
 
cmb
if ($cat = $this->lookupCategory((int)$sID)) $aCategoryNames[] = $cat;
one line
 
$ids = [1,2,3,4,5,6,7,8,9];
$things = [];
foreach ($ids as $id) {
    $thing = lookup($id);
    if ($thing !== false) { $things[] = $thing; }
}
 
cheers
 
4:14 PM
@FélixAdriyelGagnon-Grenier To get all the benefits of GraphQL while not loosing performance. Queries, mutations, 100% type safety, subscriptions, etc
 
@FaizanAkramDar Interestingly, none of these are what I find GraphQL to be useful for. Queries and mutations are select and update statements with other names. What I find it really useful for is wrapping disparate data sources, different data acquisition strategies, and data storage, in one robust interface.
Some of these data sources use SQL, others might not, others may be 3rd party apis
 
That's true, it was just an example. You can combine other days sources in hasura too
 
A database has type safety based on the data type of the column
 
Naming Things question: I want to look on an object property for a given attribute. If that attribute is not found, and the property is typed to be a given class, I want to scan that class for the same attribute. What would you call a thing where that is viable and desired?

Transitive is all I'm coming up with, but that feels wrong.
 
4:29 PM
Could it be doing too much? Like maybe should the part that detects if the attribute isn't found should be in another method or a level up in the callstack?
 
@StatikStasis Don't know... Tiffany typed earlier.
 
@Tiffany you can't push same types onto client without a lot of work
 
Probably just me
Enjoyed it
@Derick
You know you're still live right? @Derick
Watching you on Twitter
 
no
oops
 
4:31 PM
Thought I'd stopped the stream :D
 
4:46 PM
Yes, it's an opt-in behavior. The way I'm doing it is basically:

if (attribute found on property) { return attribute }
if (property is an object && attribute has interface Foo) { check that class for $attribute }
But I need a better opt-in interface name than Foo.
 
4:57 PM
@Kacper'Kadet'Donat zend_check_type is closest, the most important thing is not how you check types (you might want to write a function rather than re-use for that, I'm not sure), the most important thing to get right is when you check types ...
 
It's a bit tricky because all the different type check implementations are specialized to something -- e.g. zend_check_type requires a cache slot
 
5:26 PM
@JoeWatkins Yeah, that's basically what I've found in the code and I will probably write my own function based on that. And when, well, I should note that this is really slow and therefore be really careful with typechecks?
 
parse_ini_string behaves differently than on PHP 8.0- ・ Filesystem function related ・ #81482
 
Are you checking every property every time?
 
5:42 PM
As I'm basically implementing type checking for array entries - yes, every typed entry is checked every time type check occurs and I don't really see way around it. But type check occurs only when it's needed i.e. when calling functions, value return etc. so it should be quite rare.
 
5:53 PM
@Kacper'Kadet'Donat fyi that's the reason why wiki.php.net/rfc/arrayof was declined...
 
@Danack Oh that's good to know, and performance-wise now it'd be even harder hit because of union types and intersection types. And even harder to implement because of typed properties.
 
The only even potentially performant way to do that would be to check the type of a value when it's added. Then you can assume after that it is an acceptable type.
 
And this would be really class / object like - and we already have classes and objects.
 
@Kacper'Kadet'Donat I don't understand the words, but fyi Nikic wrote some notes about implementing full on generics here - github.com/PHPGenerics/php-generics-rfc/issues/45
 
@Danack I meant that If we performed type check of a value when it's added this would basically be a class with typed properties, not type check for arrays.
 
6:07 PM
In user space, it would be a class wrapping an array and providing type checks on insert. That's easy to write. An in-C implementation would likely be faster, but do the same basic thing.
 
And I suppose that the main problem with arrayof performance is that it'd be hard to distinguish between array typehint that could be checked in O(1) and, for example, string[] which requires O(n)?
 
cmb
@Crell don't forget about references :(
 
@cmb I wish I could...
 
cmb
nods
 
6:30 PM
Also, if anyone want to take a look at the early draft of RFC for idea that I'm trying to implement here is a link: hackmd.io/@kadet/php-rfc-shapes. I know that this is not really likely to pass but implementing thing that I'd want to see in the language seems like a good way to learn something about internals.
 
6:46 PM
> however it’s not feasible to use named arguments with a lot (10+) of possible configuration options.
Why is it not feasible?
 
It's not only feasible, it's still superior to an array.
 
@Kacper'Kadet'Donat Is it an array, or is it a property-only class?
 
@PeeHaa Every possible argument would have to be defined in place, resulting in potentially very long function definition inside of class, and still it'd not be possible to define more complex structure.
 
Long function definitions are fine imo
 
Even 12+ lines for arguments?
 
6:55 PM
Sure. Why not?
 
Number of lines is a useless metric on its own
 
I wouldn't think twice about doubling the number of those if it had a benefit
 
If something needs 12+ arguments it needs 12+ arguments
 
Ok, fair I see your point and agree with it, so yeah the 10+ argument may not be good at all.
 
6:58 PM
@PeeHaa When they have to be repeated from one place to another it gets annoying.
 
But basically ^ if you have to define same set of arguments over and over again, good luck have fun.
 
something something, when multiple parameters are going to be passed around together, they should probably be a type, rather than individual params.
 
And it would also allow to make more complex structures with nested arrays, that are properly checked and IDEs would have metadata to provide us sweet completions.
 
@Danack Sure, fair enough.
Does it happen that often that you send through the exact same set though?
 
@MarkR Nah, it's almost exactly like interfaces in typescript. Basically - arrays will still be plain arrays, that can be modified freerly (except for typed properties...) but there will be in-language way to check if array has correct keys and types via typehint.
 
7:03 PM
Personally I'd not take that approach. instances all the way... like typescript
 
./configure --help prints twice --with-expat ・ *Compile Issues ・ #81483
 
@MarkR Are you using class instances in typescript?
 
There's very little of TS I am not using, can you be more specific as to what you're asking
 
Well I meant if you use class instances for DTOs for example
 
I usually use interfaces
 
7:08 PM
So you don't use instances
 
fwiw (besides the other point) in case of complex structures I would go for a class instead instead of array
 
Or I wrongly understood "instance", which is possible too
 
const f: Foo = { a: 1234 };
console.log(typeof f);
> Object
 
yep, not Foo
 
Yes, but the object is a byref instance
 
7:11 PM
yes, but javascript's Object is the closest thing to array in PHP, well except in php array is value type and in JS object is reference type
But from type system point of view value / reference typing is not important
 
But the performance difference would be enormous. An expression creating a particular shape could determine that shape at build time, assigning it a generated ID, other shapes could compare against IDs rather than every property, and cache the result
 
>An expression creating a particular shape could determine that shape at build time, assigning it a generated ID, other shapes could compare against IDs rather than every property, and cache the result

And that'd be a class.
 
@PeeHaa maybe not often, but avoiding this, even if it's rare, sounds like a good thing todo.
 
It would be defined by a ce, but would not have class behaviour. class A and class B are not interchangable even if they have the exact same properties, but shape A and shape B would be
 
But combining different types, into new and exciting types is also that would be nice to be easier.
...
 
7:18 PM
@Danack Wouldn't it be the same if you have a DTO/configuration object/whatever and pass that instead?
Not trying to be annoying here, just trying to understand what it would add in this case
 
The nice benefits to interfaces in TS are that it exposes the object helpers so you can do things like: { ...foo, newProp: '123' }
 
Do we have spread in array with string keys in PHP already?
 
Arrays are similar to record types (simple value types) if they're typed
 
@PeeHaa You underestimate my lazyness. Being able to define easy lighter weight types is nice, not only for writing, but reading also.
 
7:22 PM
@PeeHaa Thanks I did not know I remembered that correctly
@MarkR So this syntax would be possible in PHP too in that case.
 
@Danack Well.... one cannot argue with simplifying things I guess
 
This would also allow to properly type tuple like arrays, which are sometimes used
 
Copied by values and easy to create, no separate file for example. Without array shapes they are completely useless except for maintaining internal state
 
@PeeHaa Being able to do inline shapes in TS is <3 foo(): { a: number, b: number } { ... }
 
Luckily psalm helps, but having it natively in PHP would be nice
 
7:27 PM
yep, unfortunately implementation is... not easy? Especially because typed properties and references.
 
So I have another question :P
 
reject anything with references =)
 
Wouldn't the feature be much more useful if you can define types?
 
@PeeHaa What do you mean by that?
 
@PeeHaa Honestly, with named args, constructor promotion, and readonly, I have exactly zero use for array shapes and would never use them.
 
7:29 PM
@MarkR Yeah I joked that "Typed properties and references" section would probably contain only "Too hard, lmao"
 
@Kacper'Kadet'Donat You will still have to have your types as full classes (or use built in types) right?
 
It's not a joke tbh, they're a pain in the ass and will likely be burnt in a fire at some point in the next few years if Nikita gets his way.
 
@MarkR But this will introduce another inconsistency in language, which I want to avoid at all cost. And also, this is a challenge so....
 
@PeeHaa the rfc covers both defining the type, and then being able to use it as array of those types, right?
 
It does? Me reads again
 
7:32 PM
shape FooShape {
    "str": string; // value associated with "str" key must be a string
    "num"?: int;   // value associated with optional "num" key must be integer
}
 
Yes, but say: must be an int < 10
 
though as that's after a few hundred words, you might have yada-yada'd over it.
/actually, laters, I shouldn't be on the internet right now.
 
@PeeHaa For now in my implementation uses custom zend_shape structure, which contains name, flags and entries (and later probably more stuff, but for PoC it's enough), which are stored in custom shape_table (yeah, yet another symbol table...)
 
Sorry for being blunt, how hard would it be to combine all symbol tables for PHP ?
 
probably quite easy? but BC breaking.
 
7:35 PM
I think there was an RFC for it
 
@PeeHaa This would be basically design by contract
I'm all for being able to create types like int but between 0 and 10
And in fact I the end I want to implement that RFC in a way that'd help to do that
and also make it easy to create type aliases etc
but well, that's 1) implementation detail for now 2) out of scope for that RFC
 
Yeah
 
But the basic concept is to introduce named_type_table, which would contain all information about named types - in this case shapes and classes, and potentially in the future more things like aliases
 
@Kacper'Kadet'Donat Honestly, I think you're barking up the wrong tree. DBC functionality shouldn't be limited to arrays; it makes even more sense on object properties and function parameters. Implementing that is basically pattern matching, which has an RFC and partial implementation already.

And at that point, a shape offers no advantage over an object, which already exists and works and is used all over the place.
If you really wanted to implement a new datatype in PHP, there are way more useful ones to add than shapes. :-)
 
@Crell Well, shapes are type that I'd personally want to see and that's why I'm implementing them. They are also quite complex so I could learn much about internals that could be later used for potentially better use.
And also, could you maybe name one of that "more useful types"?
 
7:43 PM
Well, don't let me stop you from learning. :-) But your odds of getting it passed are low, precisely because of what I mentioned: everything you can do with shapes you can already do with objects today.
A true vector/list type and a true-dict type. Basically splitting arrays apart into what in every other language are two different types. (List and Dictionary in Python, slice and map in Go, etc.)
 
@Crell Yeah, I know that, and I'm okay with that to be honest. And maybe in the end I will be able to convince you, who knows? ;)
 
Both have been discussed, but not implemented on the grounds that "a whole new type like that is a lot of work." But if you're up for doing that level of work anyway, I'd love to steer you toward something that would be more useful and more likely to pass.
 
Yeah, but this would need to not be based on the current HashTable, this is hard on another level and unfortunately I don't think that I have enough knowledge about data structures to do that :/
And also, which is quite funny, I don't think that this would have benefit for me as PHP developer, where being able to create quick, easy to use types that are type safe and well defined would in fact be nice to have.
I see the point, but this is really low-level feature I think?
 
Yes, very much so. It is in many other languages.
As for quick, easy to use types... with PHP 8, I can throw together a public-property class in seconds. CPP + named args > shapes.
They were added basically so that we didn't need shapes. :-)
/me has to run out for a while, BBL.
 
@Crell CPP + named args are more like records, not like shapes. Shapes are structural typing, classes (even unbloated) are nominal typing.
And one of main goals is to introduce way to do structural typing as an option in PHP (again, basically typescript interfaces / object types)
 
8:06 PM
libgd-2.3.3 does not provide GD_FLIP_VERTICAL macro ・ *Compile Issues ・ #81484
 
8:39 PM
@Jeeves They seemed to link to master, not the 2.3 branch, which does have it on latest commit.
 
9:13 PM
> GD_FLIP_HORINZONTAL
 
cmb
9:49 PM
:)
 
10:12 PM
I've discovered this and now I want a burrito.
But I'm not hungry enough for a full burrito, so I would be wasting food. But it looks yummy. o.o
 
10:30 PM
@Tiffany I like my single sided food containers to also be edge-less: kleinbottle.com
 
@Tiffany That's... hilarious.
 
I wonder if you could make sushi that way.
 
@Crell hmmmm
HMMMMMMMMMMMMM...
 
Din
11:19 PM
I am new to mysqli oop can you fetch object as array and still access the values like $user->name using a foreach? or do you have to use a while loop?
 
@Din If you fetch results as an array, you have to use []. If you fetch results as an object, you have to use ->.
 
Din
@Crell I was looking at a tutorial on mysqli oop and I seen some use $user->name in one part of the html and $user['name'] on a foreach so I didnt understand why
 
94% of PHP tutorials older than 2 years old are crap.
 
Din
yea im finding that out
am i allow to post code here?
 
If it's more than a few lines, please use a gist.
 
Din
11:26 PM
I call on my page $users = User::find_all_users(); then below I have a short hand if $users->fetch_object()) :
if i var_dump users it returns object but in the if I do a foreach it returns array but will nmot allow me to use $user->name
 
the object may implement Iterator or Traversable which allows looping over
 
@Din if you don't understand what your code is doing, you should probably be stepping it through a debugger (i.e. xdebug) to figure out what is actually happening.
 
objects use the arrow operator -> for accessing things within the object like properties or methods (for context, JS uses . for method/property/what-have-you access)
there may be an underlying issue where there's a multidimensional array... which a debugger would help with... or if you're like me and can't use a debugger on your workstation, use a bunch of foreach loops and var_dumps to figure out wtf is going on
 
Din
I see what the code is doing in procedural its a lot different than OOP and php docs only give so much info
yes i did var_dumps the foreach is where it gets lost I know it does it as an array
 
@Tiffany Why can't you use a debugger on your workstation?
 
Din
11:35 PM
I am using phpstorm and I cannot get debugger to work for me
 
What have you tried, and what are the error and/or log messages you get?
 
@Derick various reasons, but main reason is I'm too low on the beanpole to push it as a change. The code I work with now, I may actually be able to get a debugger working, but the other code base is too legacy, infrastructure doesn't really allow for a debugger to be useful. Also, I can't install PHP on it.
 
Din
I dont get any error messages if I call $user['name'] I only get and error when I try to go from $user['name'] to $user->name
 
I meant when you are trying to get the debugger to work.
 
Din
it actuall closes my phpstorm down
 
11:38 PM
That makes no sense to me.
 
memory issue?
 
Din
every since the last windows update
 
group policy?
 
Din
the last windows update knocked out composer node and phpunit
 
11:57 PM
Why would PHP-DI use singletons by default? php-di.org/doc/scopes.html
It looks like below there it suggests just not using dependency injection as an alternative to not having a singleton injected
Or injecting the container into the constructor itself. I thought that using the container directly anywhere other than bootstrapping was frowned upon
 

« first day (3999 days earlier)      last day (931 days later) »