« first day (3244 days earlier)      last day (1929 days later) » 
00:00 - 12:0012:00 - 00:00

00:52
should I replace my ajax calls to AMP PHP script?
 
5 hours later…
05:31
Good morning
06:09
posted on September 02, 2019

hi there
i have a question about mpdf
this is the link guide of the mpdf installation
the first step is
$ composer require mpdf/mpdf
where do i write that line of code
iam using PHP in localhost (Wampserver)
06:35
\o
06:48
o/
Feeling better now it's no longer Monday, Joe?
a little
today hasn't proved it's not monday yet ...
07:09
morns
07:57
morning
I have prepared [tl;dr](https://gist.github.com/brzuchal/05e8641e95f2402acb225befcb2c20a1#tldr) section in my [object initializer](https://gist.github.com/brzuchal/05e8641e95f2402acb225befcb2c20a1) raw proposal idea and would like to hear some comments.
Any ideas, comments?
Is it worth?
I can see it's usage in featured annotations to initialize object mapped annotations.
I'm not sure what the benefit is vs using an array?
@MarkR array could be only a replacement in case of casting to an stdClass object
I used it in the example only to show that undeclared and by variable name properties can be set using that syntax as well
@Girgias Would be good to see you on Thursday!
@MarkR The goal is to initialize object properties through public properties or setters in single expression that can be shorter
Sorry, I meant more along the lines of:

class X {
  public static function create(array $input): self {
     $x = new self();
     foreach ($input as $k => $v) {
       $x->{$k} = $v;
     }
     return $x;
  }
}
08:09
@MarkR I consider that example as really bad code, hard to maintain hard to guess what happens
No type checking at create() method call
@NikiC Grr... committing things to PHP-7.4 when I'm making a release :-/
@MarkR And going further it's a bunch of expressions and a loop vs. single expression
and your class{ prop=x; prop2=y; } has type checking at call time?
@MarkR Yes, they're typed properties and even create() - named constructor has typehints
I wasn't aware that $x->{$k} could bypass typed properties.
08:15
In a future would be possible to remove stdClass and run $dynamic = "dynamic";echo json_encode(new {undeclared = null, {$dynamic} = new DateTime('now')});
{"undecloared":null,"dynamic":{"date":"2019-09-03 10:12:53.000601","timezone_type":3,"timezone":"Europe\/Amsterdam"}}
@MarkR if declare(strict_types = 1); then it'll throw TypeError
Fair enough. I can't say I fully understand the benefits vs passing an array to the constructor or some other factory method, especially as they could enforce additional filtering, but I can't say im either for or against it
ah I see it's based on the C# version
Good, any others comments?
Java haa something similar with new Foo() {{...}}
08:31
Hello everyone, does anyone have a link where i can find all the characters that are in the Latin script (Regex PHP)?

For exp: this Regex preg_match('/[^\\p{Common}\\p{Latin}]/u', $string) matches words that have only latin characters, i would like to know what are those characters.

Thanks in advance!
08:47
I don't like it, I like the parts of it that are basically object literals, but statements as arguments to what looks like a constructor is wrong, and could just be a constructor @brzuchal
moving calls from the callee side to the caller doesn't really seem to have any obvious benefit, except hiding the implementation details of what should be a constructor in a different location in source code (at the call site instead of implementation) ...
@MarkR Different thing but similar use of brackets and name and values
@JoeWatkins So object literals ok, calling methods not, right?
I was looking for an option for fast DTO construction, and as a solution for featured annotations
a non strange implementation of object literals I can get on board with, I couldn't vote for this as it is though ...
I usually chain setters for DTOs.
@JoeWatkins so to clarify cause um not-sure of my english understanding, as far as it is just assign to property like new Foo() { foo = 123, }; that's ok with you?
08:54
@JoeWatkins Awesome thanks! Yay!
How would you handle foo having additional validation?
@MarkR through __set(string $name, $value): void {} optionally - that's built in PHP functionality which already exists
oh hey, never take what I say as authoritative, I'm wrong a lot of the time, get input from other voters before making decisions about what to actually do ...
@MarkR besides typed properties already handle type validation
@JoeWatkins Ok, ok. I can prepare some draft of RFC and send it to internals and think of some straw polls, right?
maybe there's really good justification for the strangeness that I don't see, and that you haven't communicated ... but someone might be able to communicate it ...
08:57
I think this is what is tripping me up:
$foo = new Foo(123, true) {
protectedString = "bar",
setProtectedInt(321),
};

Is that meant to be inside a class method so it has access to protected members, or is it external?
@MarkR wat is that
external, there is __set() which writes protectedString as it is not-accessible then __set() is called
yeah what is that, why is there constructor arguments and properties and method calls ?
second setProtectedInt is a public setter
@NikiC We're going over @brzuchal's proposal @ gist.github.com/brzuchal/05e8641e95f2402acb225befcb2c20a1
08:59
I missed the constructor arguments, why does the object need more initialization than the constructor implements ?
Well, to get the obvious thing out of the way: Object init syntax must only be available if there is no ctor
yeah, having a ctor and initializing inline makes very little sense ...
@JoeWatkins I thought there can be a object with ctor for required arguments and a bunch of other properties with default values which don't need to be overriden but when I need to pass for eg. one of the last ctor args which is at the end on arguments with default values and they're public - then I can set them after ctor
How about DTO's when identity is required and the rest has default values, and there is plenty of properties?
Why to create ctor for all, sure I can create object and set them later but would always need to assign created object into variable and then assign it's properties and then and only then able to use that object.
In case of factory method or builder etc. this would be in single return expression
Does that make sense?
@JoeWatkins I've added method calls cause there are no built in setters in PHP, in C# which implement this docs.microsoft.com/en-us/dotnet/csharp/programming-guide/… object initializer can assign value to property and handle it through setter, but in PHP we often use function setters and that's why it appeared in this proposal
I don't like the idea that you can initialize protected properties from outside (if I'm reading your examples right)
slow down a little, you're overloading me ... I understand the words you are using, what I don't understand is your approach
09:07
@MarkR I used protected in the name on purpose in the example it is handled through public interface
ah okay, now I understand what you mean about using __set
1. class Foo with public properties without constructor could be instantiated and all properties initialized using object initializer like new Foo() { prop = "value", };
it's fine to have a use case in mind when you're designing a feature, but you don't design a feature after a use case in the way you seem to be doing ... you design the feature to be logically consistent and conventionally consistent ... having a declared (non-named) constructor and the ability to initialize the object inline in exactly the same way as a constructor should is not logically consistent, is the bottom line ...
@JoeWatkins Ok, so NO ctor + initializer possible, what in case of DTO which needs identity and the rest of properties are public and typed?
show me some code
look, if you write the feature, and it turns out that it's not actually suitable for the use case you had in mind, then it's simply not suitable for the use case you had in mind :)
saying "I done this weird thing because this thing is missing" is not justification for the weird thing, it's motivation to implement the thing that is missing ...
09:13
class Customer {
    protected Uuid $id;
    public string $name = "";
    public function __construct(Uuid $id) {
        $this->id = $id
    }
}
$customer = new Customer(Uuid::uuid4());
$customer->name = 'John Doe';
okay this is simple
Customer cannot exist with it's identity but can have default values, like name, etc.
^ I'd still probably just pass an array defaulted to [] as the second param to the constructor
I need two statements to create an object and initialize public properties, what if there is 20 properties? Pushing them into ctor would be bad cause I would have to know all default values from ctor just to replace the last 20th argument, right?
new Foo('expected', [ 'optional' => 1]);
09:16
@brzuchal If you want to use initializer syntax, drop the ctor...
class Customer {
    public Uuid $id;
    public string $name = "";
}
@NikiC how to force requirement for $id then?
@brzuchal It's a typed prop without a default value
So you can require its specification in the initializer
This feature would make very little sense if everything was optional, imho
@NikiC exactly so it's in false state without $id
It's useless without default values which are types = classes cause there is no option to assign default value for them without ctor
class Customer {
    public Uuid $id = Uuid::uuid4(); // that's not possible
    public string $name = "";
}
that's a very separate problem
@JoeWatkins you're right
09:19
@brzuchal I still don't see the problem
It would obviously be not allowed to construct the object without specifying $id in this case
You couldn't reach the invalid state via the initializer syntax
$customer = new Customer {
    id = Uuid::uuid4(),
    name = "John Doe",
};
Right?
^ that would be fine?
that's all I expect to be supported really
@NikiC Yes, like above
09:20
(with whatever syntax is possible, I'm not sure if that syntax is)
Should it allow to initialize undeclared properties?
Should it allow to initialize properties by variable with name?
@brzuchal no :D
no ? but objects support that, a constructor would support that ... why ?
09:22
@NikiC PHP alows that, why not?
Because we have no obligation to repeat past mistakes in new syntax
@brzuchal I wish though this would be possible...
@NikiC wouldn't it be better to fix past mistakes with for eg sealed class Customer {} which prohibits creating dynamic properties?
^ that I can absolutely agree with
@bwoebi Me to
09:24
@NikiC hmm, I'm not sure in this case, it feels like missing support for object model ... if that's a mistake then let's fix it, but the thing should support the model as it is imo ...
Going alone in the future I might see a future improvement with readonly keyword for properties - meaning they can be assigned through ctor or initializer
@JoeWatkins Agree
$dynamic = "myProperty";
$customer = new Customer {
    id = Uuid::uuid4(),
    name = "John Doe",
    undeclared = 123,
    {$dynamic} = true,
};
It's just like removing $self-> in from of the whole list
readonly would be something of a waste of time IMHO @brzuchal. A temporary measure to act as a patch to property getters and setters
@brzuchal btw. I feel the {} around $dynamic are redundant
@bwoebi it would be consistent with current syntax, right? $self->{$dynamic} = true;
@brzuchal $self->$dynamic = true; is valid as well
09:27
Oh, ok then :)
@JoeWatkins I'm not sure I agree. That depends on how you phrase this feature.
Assuming it enforces that you must initialize properties without a default, it's not really just a syntax for assigning arbitrary properties
@NikiC without that it would not be possible to create object just for json_encode
It's specifically a syntax for initializing objects into a well-defined state by using metadata on declared properties, and as such I think it would make more sense (and be more useful in terms of bug prevention) to limit it only to declared properties
But we're talking about undeclared properties now, right?
@brzuchal Why would you use this for json_encode? For json_encode you use stdclass
09:30
1 hour ago, by brzuchal
In a future would be possible to remove stdClass and run $dynamic = "dynamic";echo json_encode(new {undeclared = null, {$dynamic} = new DateTime('now')});
that would produce an stdClass :D
1 hour ago, by brzuchal
{"undecloared":null,"dynamic":{"date":"2019-09-03 10:12:53.000601","timezone_type":3,"timezone":"Europe\/Amsterdam"}}
@brzuchal I'm not sure that's optimizing for the right thing.
one expression
@NikiC we can discuss it in the future, I'm good with declared properties for now, cause I'd like to use them to my featured annotations
Did I miss something and annotations are meant to be actual executable code now?
09:34
@NikiC that makes sense ... but not more sense than similar loose justification you can give for including it like missing object model support, and playing with the definition of "well-defined" (to mean something other than "explicitly declared") ...
Gathering all the comments I presume it is worth to try with an RFC for object initlializer which allow initalizing public properties, right?
@MarkR Working on a concept
@JoeWatkins All Eloquent model use undeclared properties
@JoeWatkins The other part to consider is whether you want to interact this with __set or not. I guess if you allow __set then allowing dynamic properties as well may make sense
I think it has to invoke magic, doesn't it ?
@JoeWatkins magic is invoked on non-existant or not-accessible property assigns
yeah I know ...
09:43
Should i stay or should i go - with that proposal?
I kinda like the idea of { } notation for objects without the need to quote every field name.... still don't know why you don't just use an array
@MarkR passing array to method doesn't invoke any type checking, only that it is some array
nikita is saying that he would prefer to be able to define the feature as "specifically a syntax for initializing objects into a well-defined state by using metadata on declared properties" and so doesn't want support for undeclared properties (to reduce surface area for bugs and so on), and I'm saying I'd like to define it in more general terms as an object initializer with support for the object model as it is, with undeclared properties (and implied support for magic) ...
Type checking occurs when you try to set the actual parameters
@JoeWatkins how about using spread operator in a future? new Foo { ... $array } @MarkR that would involve your array preference :)
09:45
go with what nikita says ...obviously ...
As soon as you introduce the array, it makes the purpose of { } pretty much redundant @brzuchal so splatting it out wouldn't make much sense IMHO.
@JoeWatkins I will go with what you say
I'm saying do what nikita said ... you want him to be able to defend your idea ;)
@JoeWatkins how to convince Nikita?
he likely wouldn't vote for the thing I imagine, I'll vote for the thing he imagines ...
@brzuchal it's highly likely that I'm wrong, and I think I said that at the start ...
09:48
It can be a separate voting, right?
I think not, this ought to be a resolved question before you even put it up for discussion ... it's a core aspect of the feature, you don't want to seem fluffy on the details ...
Ok, I will start writing on what Nikita says.
I said "if it's a mistake let's fix it", that was disingenuous, I know it was a mistake ...
Will try later to ask Nikita about a consent for undeclared properties support.
@JoeWatkins eh, I think your version is fine as well
probably...
09:55
@NikiC with support for undeclared properties?
@brzuchal You should probably just mention both possibilities in the RFC :)
@NikiC Perfect, thx
I just realised that the { ... } notation would work great for initialising all of the models I have, if I hadn't spent the past few days changing them all to:

$db->create(Something::class, [ ... fields ... ]);
10:12
@Derick so fpm master is executed as root and executes minit (and so preload), then forks, setsuid on children and rinit and so on ... so the preloaded stuff is executed as root ... but worryingly, it's still going to be executed as root after this patch, if that's a big security issue then shouldn't opcache prohibit that whatever ?
Youch
@JoeWatkins Yes, I agree with what you say. But without Dmitry's patch, it's even worse, not?
yeah, it's an improvement in the form of some degree of control ...
@JoeWatkins it won't be executed as root after this patch
is it typical to run fpm as root?
this stops opcache from starting completely ?
yeah it won't be executed as root, my bad ...
10:21
At least it stops it from preloading, not sure if it prevents opcache start
@NikiC I think it's not typical, but it allows it ...
@NikiC yeah
okay I read it again, presumably if I start the process as krakjoe and set the user as "web", it doesn't set the user, am I reading it wrong ?
would someone be so kind as to explain wtf the difference is between "component-oriented" programming versus "object-oriented" programming?
the wikipedia entry for component-based programming isn't sinking in
In docker the default is to run the php-fpm process in root if that counts for anything.
I dunno what fpm does in those circumstances, but think it sets the user, shouldn't it do the same ?
Would need to be chained with a container escape
cmb
cmb
10:28
@JoeWatkins, preload_user is only relevant if code is executed as root.
cmb
cmb
if (geteuid() == 0) {
I see that, but don't understand it, that's what I'm saying ...
@JoeWatkins fpm only switches user if run as root as well
I'd assume that's why
right, okay, I was just trying to find that out ...
okay good, ship it ...
also, I vote retag, it should be in rc1 ... this is why we tag early ...
/cc @Derick
10:33
sigh
it's okay, failure is built in, it's php ...
yes, but undoing a tag, and retagging takes 10 times as much time, as the docker container build doesn't handle this
we still have 5 more rcs...
So unless I can tag the new one as RC2, I don't think this is something I would like to do now
we do, but for a few hours it would have been included in this one though ...
is peter getting involved in doing any of the builds or anything yet ?
10:36
Surely in finest tradition of PHP numbering, just tag it RC3
it was really easy for me to retag because I didn't use any of that stuff, so two commands for me, 10 seconds ... if it's lots of effort then I'm not so sure ...
no, I can't bring myself to say it's okay ...
you can't release this knowingly into the wild
why not?
even in an rc, it's a pretty nasty flaw
@NikiC I can't tell what it might lead too, but if this were reported as a bug, we would classify it as a security bug, right ?
so I don't need to be able to tell what it might lead too ...
known sec bug in rc feels wrong to me ?
cmb
cmb
RCs are not for production, so no sec issue, IMHO
@cmb that
cmb
cmb
10:42
also PHP 7.4.0RC1 Windows builds are running
c'mon that's so weak, ask people to test RC's and they will find their way to production and you know it, and you want that ...
I vote extremely hard, very loudly, that you should not make any RC with this bug present because the fix already exists, sorry if rebuilding takes time, that's shit ... but not as shitty as the alternative, and it really is shitty ...
Having spent 20 minutes now discussing the security implications of it on a public, searchable forum. Any miss-use of said security bug is likely to lead back to the logs of this conversation, that would potentially lead to people to a loss of trust...
The narrative wouldn't be that there was a security bug, the narrative would be there was a security bug, it was known about, and nobody cared. Not a good look. Just my 2c.
cmb
cmb
well, RM's decision
@NikiC, https://lxr.room11.org/xref/php-src%40master/Zend/zend_execute.c#1084
shouldn't that be IS_CALLABLE_CHECK_SILENT | IS_CALLABLE_CHECK_SYNTAX_ONLY
@cmb why?
cmb
cmb
working on ext/xml stubs, callable won't work, e.g. for
https://github.com/php/php-src/blob/master/ext/xml/tests/bug30266.phpt
s/won't work/triggers assert
10:55
@JoeWatkins @NikiC found that Java has "double brace initialization" wiki.c2.com/?DoubleBraceInitialization and they do use method calls as well, this is a known on SO hack around the anonymous class and initializer block
Not exactly the same but works similar
@cmb on which call?
not seeing any obvious callables in there
cmb
cmb
To clarify, these are not actually callables (accept '' as well), but in this case it should work, shouldn't it?
@cmb those aren't callables
they are strings, not callables
they're method names
11:00
[$this, 'startHandler']
Unless it uses f in zpp, it's not a callable
cmb
cmb
Ah, thanks!
Gods, property_exists is such a mess
has_set_exists
11:03
It completely ignores visibility...
It says static properties exist on objects
It says unset properties exist
And I'm probably not allowed to fix it
And then you see in the documentation changelog:
> 5.3.0 This function checks the existence of a property independent of accessibility.
WHHHHHHYYYYYYYYYY
see I had never looked, and I was happier ... it's your fault for looking ...
I just thought the has_set_exists thing is a pita ... but this is really horrible ... what have you done ?
Damn I didn't know it was possible, but method_exists is even worse
Reports private methods from parent classes as "existing"
... and that was the last we ever saw of Nikic... some say a body was found matching his description more than 2 weeks later, at the bottom of a pit filled with scorpions. A mangled note in its hand read "I can't deal with this shit"
@Danack I have no idea what I just watched.
11:15
Oy, I really think we should use JSON syntax for the braces, maybe allowing for unquoted literals as well, even though it removes the ability to specify constants for property names.
a clip from Hogans heroes, and a hint to not be too negative.
$customer = new Customer {
    "id": Uuid::uuid4(),
    "name": "John Doe",
};
And various QOL improvements, such as permitted trailing comma.
@LeviMorrison it's not PHP like, why to change into JSON, there was an RFC discussion in 2011 about that and it didn't go well AFAIR
It's not intended to come off as negative, it's just very dry British humour
@brzuchal Because allowing JSON to drop directly into PHP has definite value.
11:21
// proposed syntax
$customer = new Customer {
    id = Uuid::uuid4(),
    name = "John Doe",
};
// is just a simplification of
$customer = new Customer;
$customer->id = Uuid::uuid4();
$customer->name = "John Doe";
Yes, I agree with those semantics exactly.
And that way we use the same tokens as assignment
That's not JSON though?
If you just remove new Customer then "default" it to a generic object. Maybe not stdclass; maybe it makes sense to use an anonymous class instead. IMO not that important, but maybe there is some case I'm not thinking of.
Why should that be JSON? If it is PHP look here wiki.php.net/rfc/objectarrayliterals and see the discussion marc.info/?t=130723757000001
11:23
@brzuchal That was 2011.
Further, it suggests changing array literal syntax, which was obviously going to fail.
@LeviMorrison Was thinking to improve it lata with removing class and by default use stdClass
But that would be to complex for me to handle now. Besides I'm not sure if I can deal with proper patch for what I wanna propose :/
Plus, there is one game changing bit: typed properties are going to make this situation more common.
Would you stick with the = style, or use :, or stay with existing array styles of => thus making changing an array to an object just be a case of replacing [] with {}
@MarkR I would stick to = cause that's the way we assign everything, and array key pair is a different thing
If we were to change the semantics at all, I would say that at the end of the brace initializer that we check that all properties that are not defaulted are initialized.
11:26
I'm afraid that if I mention "JSON" term somewhere or using : instead of = people would put much hate on me on internals
@NikiC Probably didn't think about it hard enough.
Did we make it final and remove its constructor?
If so, it can be "fixed", probably.
@brzuchal Perhaps I'm misinterpreting you, but => is how all maps are done in PHP. Unless you expect everything in { } to be the equivilent of $this.lhs = rhs; } which would probably explain your use of functions inside it
@MarkR Yes, I expect it to be equivalent to $instance->... = $value what's why was including method calls as well previously
I see, sort of like VB.NETs with / endwith
Crap I think it cannot work with anonymous classes.
$instance = new class {}; // already valid syntax
$instance = new class { foo = "bar"} { public string $foo; }; // looks odd
11:38
The "obvious" probably completely dumb solution would be an alternative to "new"
@brzuchal Of course it "works", it's just goofy.
@LeviMorrison Would you vote for that?
Its syntax and semantics are goofy, unfortunately.
Construction should have gone after definition :/
Although it's slight duplication, not dropping the () brackets would be needed anyway, if you wanted to (and I kind of guess you would) use that syntax for functions that take named parameters anyway:
$customer = someFunctionThatTakesParamsByName({
    "id": Uuid::uuid4(),
    "name": "John Doe",
});
Classes are still not first class citizens, right?
You can't do
11:40
@Danack but braces are optional when instantiating an object
@MadaraUchiha Correct.
<?php

$cls = class { public string $foo; }

$instance = new $cls { foo = "bar" }
Correct... kind of.
It's very stupid but you have to instantiate an object, then you can do new $obj.
I'm sure there's some reflective incantation I can perform to reach this effect, but that's not what I'm after
@brzuchal but not if you want to pass parameters. And this looks very much like a 'passing parameters' thing. I don't particularly care, just pointing out that having to have () to use that isn't bad.
11:43
$cls = new class() { public string $foo; };
$instance = new $cls { foo = "bar" };
// this works
Of course, that only works if you know the args you want to use at definition time, which limits its usefulness in at least a few places.
@LeviMorrison My brains throws a parse error on that first line
$reflection = new ReflectionClass(new class {public string $foo;});
var_dump($reflection->newInstance());
What is the value of $cls in your example?
Yeah, it's goofy. I think I was around to vote on that; can't remember.
@MadaraUchiha It's an object with an un-initialized $foo property.
@Danack You mean in case of anonymous class object initializer?
11:45
You can create a new class by passing any other class of its type to new?
You can do new $obj and it will work, yes.
@MarkR looks like it is true indeed 3v4l.org/TsRc9
Well TIL. I'd love to know the reasoning behind that.
It's just how it has always been: 3v4l.org/pZQbI
@LeviMorrison Oh :D
11:50
@brzuchal It's because it doesn't have anything to do with it being anonymous. It's just something the language supports.
How interesting. I don't think I've ever seen that come up in any code I've used.
@LeviMorrison Yes, I see. Was looking in manual and also didn't found that
new $this; // also works :)
@brzuchal php.net/new mentions it (very briefly)
@salathe Thank you! TIL :)
00:00 - 12:0012:00 - 00:00

« first day (3244 days earlier)      last day (1929 days later) »