« first day (3067 days earlier)      last day (1895 days later) » 

5:33 AM
helllo
:)
 
 
2 hours later…
8:00 AM
newspeak propagandistic language marked by euphemism, circumlocution, and the inversion of customary meanings
 
8:50 AM
@bwoebi can I get an hour on your mac at some point ?
 
@JoeWatkins I'm trying to debug a buffer overflow (I think) but am struggling to trace it with valgrind. How should I use a proper debugger to maybe step through some breakpoints and track it all a bit closer? gdb?
Also o/
> This is probably caused by your program erroneously writing past the
end of a heap block and corrupting heap metadata.
 
yes, gdb, read about hardware watch points - basically watch *HEX where HEX is address you are interested in, it will break any time HEX is changed ...
also there is address sanitizer, which is quite good at catching memory errors also, though I forget if it's any good at buffer overflows, you should read about that too whatever ...
asan is part of clang, but supported by gcc also, use -fsanitize-address flag
 
Cool thanks. :)
 
9:40 AM
Hi
anyone worked with magento rest apis?
 
9:55 AM
@JoeWatkins sure
when?
 
10:19 AM
maybe tonight, probably tomorrow, I'm still reading about this page allocation thing, the api is slightly different to linux
 
10:46 AM
can anyone on linux do a test of github.com/krakjoe/trace for me with the "build" script please ?
 
^ I can
 
> fatal error: libelf.h: No such file or directory
 
sudo apt install libelf-dev libdw-dev
 
Usage: php-trace [options] [flags] -p <target>
Options:
           -d --executor   <hex> Executor address          (default auto)
           -d --depth      <int> Maximum stack depth       (default 64)
           -m --max        <int> Maximum stack traces      (default unlimited)
           -f --frequency  <int> Frequency of collection   (default 1000)
Flags:
           -s --stack                             Copy variables on stack from frame
              --with-array-elements               Copy array elements
Seems happy.
 
10:54 AM
cool, thanks ...
glad I don't have to go through headache of proposing inclusion ... it's not the tidiest way to build a thing that should be in php-src, but things in php-src tend to die, and I don't want it to die ...
 
11:14 AM
@JoeWatkins check your twitter dms
 
11:24 AM
krakjoe@nevis:~$ ssh joewatkins@localhost -p 2222
ssh: connect to host localhost port 2222: Connection refused
 
one 2 missing
 
excellent, I'm in ... thanks ... can you leave it open for a couple of days if possible ?
 
I can
 
thanks, I'll hopefully get to it tonight, but maybe tomorrow ... and then tomorrow is monday so might have real work to do, so maybe tuesday ...
I may also need your brain at some point :)
back to lunch, catch you later ...
 
enjoy your lunch, see you :-)
 
11:37 AM
struct {
    zend_value value;            /* value */
    union {
        struct {
            ZEND_ENDIAN_LOHI_3(
                zend_uchar    type,         /* active type */
                zend_uchar    type_flags,
                union {
                    uint16_t  call_info;    /* call info for EX(This) */
                    uint16_t  extra;        /* not further specified */
                } u)
        } v;
        uint32_t type_info;
    } u1;
    struct {
        uint8_t a;
        uint8_t b;
^ Could I re-use the definition of zval.u1 inline here, rather than a copy paste?
 
 
2 hours later…
1:11 PM
Tests can't be run with shared extensions – #77717
 
 
2 hours later…
3:09 PM
@NikiC did you get a chance to see that patch I put forth for that memory leak? Want me to open a bug for it?
 
3:36 PM
Translation problem – #77718
 
 
2 hours later…
5:12 PM
Quick MySQL question
When I'm in a transaction, if I issue SELECT queries will I be able to see the intermediary state?
Or will I see the state before the transaction was started?
(I'm about to do a scary manual operation spanning multiple tables and want to verify everything looks good before committing the transaction)
 
@ircmaxell could you please share the link for it again?
 
Behavior of strtotime() and new DateTime() documentation utterly insufficient – #77719
 
@ircmaxell looks pretty nice :)
@JoeWatkins kinda surprised there hasn't been any outcry over that weakrefs mail
 
Mar 7 at 16:49, by ircmaxell
diff --git a/Zend/zend_API.c b/Zend/zend_API.c
old mode 100644
new mode 100755
index 8bcd175be4..f44b5d8b64
--- a/Zend/zend_API.c
+++ b/Zend/zend_API.c
@@ -3346,6 +3346,10 @@ check_func:
                case IS_OBJECT:
                        if (Z_OBJ_HANDLER_P(callable, get_closure) && Z_OBJ_HANDLER_P(callable, get_closure)(callable, &fcc->calling_scope, &fcc->function_handler, &fcc->object) == SUCCESS) {
                                fcc->called_scope = fcc->calling_scope;
+                               if (fcc == &fcc_local && fcc->function_handler->common.fn_flags & ZEND_ACC_CALL_VI
 
5:28 PM
G'day, Room!
 
5:52 PM
@MadaraUchiha You can't .. since none of the queries will be executed in a transaction until commit function is called. So you cannot see the result of a select statement before the transaction is started
 
6:39 PM
@Shafizadeh unless there's some MySQL-specific thing you're thinking of here, that's not how transactions generally work; depending on the DBMS, the affected tables/rows are either locked or versioned
so yes, in most cases, you should be able to see the intermediate state if you execute a SELECT on the same connection where the transaction is in progress
 
ah I see, I wasn't aware of that
 
Indeed, you can.
 
7:35 PM
why the fuck is php resetting the cwd between execute and (request) shutdown instead of after shutdown?!?
Why is that even a responsibility of php_execute_script() instead of php_request_shutdown?!?
Obviously, cwd-relative paths then stop working in destructors and shutdown functions...
 
just a question: I have some thoughts about a rfc proposed to the internals list. Is it okay to send my thoughts to the list as I am no internal (but just stalking the list) or is there a better way to communicate with them?
 
@kuh-chan Toss it around here first methinks, before you put it up on internals
but in general, you can just send an email to the list even if you aren't a regular.
Make sure your email client is set to reply-all by default though, that tripped me more than once :D
 
7:53 PM
okay - it's about the locked class rfc. I think, the idea is a good one. But I don't think it should work with classes implementing __get or __set. Either I want a locked class or not. There should be no implicit unlocking through magic methods.
 
@kuh-chan there's no special membership requirements, you're free to email the list with any relevant thoughts.....
 
@kuh-chan Hi :) I just had the same feedback in a different off-list discussion, actually
my reasoning was that you might implement one magic method but not all of them, e.g. locked class Foo { public function __get($p) { ... } } would effectively mean "locked setting, dynamic getting"
I can certainly see the appeal of just rejecting the combination, though
 
@IMSoP the difference between dynamic properties and unset() on defined props, is that the definition remains, unlike for dynamic props which are removed altogether.
unlike JS which has no concept of a property definition
 
@bwoebi unset properties are a peculiar beast; they don't show up in var_dump() or even serialize() output, and trigger a NOTICE when trying to read them; but as soon as a value is set, they "remember" their previous definition
 
8:08 PM
they do show up in var_dump, at least starting php 7.4
 
not unless it's landed in the last few days
```
php > $b = new B;
php > unset($b->foo);
php > var_dump($b);
object(B)#2 (0) {
}
php > echo PHP_VERSION;
7.4.0-dev
 
hmm, only for typed ones I guess then?
 
yeah, unset typed properties are even weirder
they're like the 5th Element of PHP values
 
haha
 
php > class C { public int $foo; }
php > $c = new C;
php > unset($c->foo);
php > var_dump($c);
object(C)#3 (0) {
  ["foo"]=>
  uninitialized(int)
}
 
8:11 PM
yeah
should probably also show unintialized defined props in var_dump
but that's to be discussed with @NikiC at least ... what do you think?
 
@IMSoP If I really want to have locked setting but dynamic getting I can implement __set and throw an exception.
By the way - I've seen your comment to the pull request. IS_FINAL has changed from php 5.* to 7.*
 
ah, that's interesting; I noticed the value is in the manual, but I guess anyone relying on it is Doing It Wrong
 
But anyway @IMSoP touching the unset()-ability of properties is a no-go for me as well.
 
because of the lazy-loading hack, or references, or something else?
 
both points
 
8:18 PM
the lazy-loading still feels to me like "well, don't mark your classes as locked then"
references are more problematic, though
 
@IMSoP I want all the features of locked, except for the unset-part though
 
that just feels weird to me
"I want this class to be fully defined, except for The One Weird Trick"
 
and tbh … I think we rather should make all classes locked by default with some exemptions like stdCLass
 
it would be nice, but I dread to think how much code would break
I suppose with a long deprecation phase
 
@bwoebi And the alternative would be... mutable class?
 
8:22 PM
@IMSoP not so much - actually.
@kuh-chan for example.
or ... you just implement trivial __get/__set()
 
given that it doesn't even raise a notice right now, the only way to find out would be a whole bunch of static analysis
 
if __get/__set exist, make it mutable by default
 
I know fixing it is trivial - most cases are probably just "oh, yeah, it should just declare that property, duh" - I just think there's likely to be a lot of code out there where people don't even realise they're using it
 
I think, the removal of old style constructors will break more code
 
yeah, well, I'm not convinced of the value of that, either
they didn't seem to be doing that much harm
tbh, though, if the consensus was to deprecate instead, I'd be happy
 
8:36 PM
Incorrect IP set to $_SERVER['REMOTE_ADDR'] on the localhost – #77722
 
it's been an interesting learning experience playing with the implementation, even if nothing else comes of it :)
 
And nikitas comparison rfc will also break a lot of code. Yes, it was tested on some framework code bases. But most of them follow at least psr-2. When I look into the code base at work... nope.
but tbh - a lot of code out there will never reach php 8. At work we just upgraded our biggest product from 5.2.* to 7.2. (and I hope, we'll upgrade to 7.4 when it comes out.)
 
@kuh-chan yeah, we need some measure of what the impact will be on real code
 
21 mins ago, by bwoebi
and tbh … I think we rather should make all classes locked by default with some exemptions like stdCLass
this. aka +1. or whatever the kids are doing today to indicate approval.
 
by the way - as I don't follow the internals list long enough. what is the reason of new features not getting namespaces? especially the sodium function names are so extremely long now
 
8:52 PM
with sodium in particular, there was a long discussion about it
I think it mostly boiled down to not being sure what exactly the naming convention for internal namespaces should be
PHP\* is reserved, but nobody's ever really defined what it's reserved for
 
Wes
php is consistent in being php
or maybe the same reason pass by reference is supported by new features: never admit you are wrong
(i am being ironic, btw. hi new people)
 
o/
 
Wes
\o
did you watch the new F1 anthem video? @PeeHaa
 
Nope not yet
 
9:02 PM
Yeah cannot do it right now. People are sleeping here :)
 
Wes
where are you in the world now peehaa sandiego?
 
Turkey
 
Wes
reminded me i need to re-start the diet
 
@PeeHaa are you going to dutch php conference?
 
@NikiC can you investigate why chat.stackoverflow.com/transcript/message/45589366#45589366 is the way it is? Feels really weird (not that you should use cwd relative paths, but encountered that in a legacy app where something was put in a register_shutdown_function())
 
9:09 PM
@Danack Nope. Most likely will not be in NL at that time and last time I checked their prices it's way more than I would ever pay for a conference
hmmm just checked and although still plenty of money it's les expensive than I thought
 
@PeeHaa yeah, it's not cheap, but maybe you mixed up dpc with that other conference ipc, is it/
 
Could very well be mixing things up. I remember prices like 1200 or something
 
phpconference.com/php-development/a-case-for-generics-in-php - could someone let Chris know, we don't need a stronger argument....we need an implementation....
 
@kuh-chan if you want the history on sodium's long names, see https://externals.io/message/97695 and https://externals.io/message/98146 and https://externals.io/message/98218
tl;dr the original extension used namespaces, but there was no precedent for namespaces in core, so some people felt like it was "changing policy by the back door", and a secondary vote ended 25:13 against
 
Wes
@Danack lol
> idea people
 
9:35 PM
`PHP is not really a language where You\Use\Things\Like\That , I'm all +1 to use_things_like_that() instead :-)`lol
The discussions reads as if it should be discussed for php 8 if namespaces should be used for core stuff and how to name them. Wouldn't it then be time to open such an rfc?
 
> how to name them
Well, there's about 50,000 person hours of stuff to do.
 
Wes
9:47 PM
locked classes is horrible. i mean i will never bother adding "locked"
i don't hate dynamically defined properties enough to add locked all over the place
i just won't create properties dynamically, or unset them
unset($o->prop) is something that should be removed in PHP8, possibly alongside the introduction of get/set{} syntax
i think it's not possible to remove unset($o->prop) because people use it to overload properties dynamically
 
@Wes I do hate them. The number of times I've been burned because I thought the prop was one thing, but is another
 
Wes
10:04 PM
class Foo{
    use TraitImplementingGetSetIssetUnsetMagicMethodsThatPreventsPropertiesFromBeingDynamicallyDefinedAndRemoved;
}
i would rather write that, than locked class Foo, tbh
i could live with a declare(strict_properties = true);
 
@Wes so don't bother adding it then? ¯\_(ツ)_/¯
not really sure how a declare would be any different
unless it's just the name you hate?
 
Wes
i hate the name quite lot, but in particular i hate the visual noise... php is very verbose already
 
how would a declare be any less noisy?
 
Wes
it's on top on its line, not near important stuff
also no need for a new keyword
and maybe one day we will get namespace-scoped declares
> The “locked” flag is not applied automatically to sub-classes.
 
I'm happy to debate details like inheritance
I personally find declare much uglier than real keywords, though
 
Wes
10:17 PM
a class inheritance tree is either all locked or not locked
don't think it could work otherwise
declare is very ugly, but at last it's not in the way
 
my logic for inheritance, as it says in the RFC, is that a sub-class can add declared properties, so why should it not be able to add dynamic ones?
 
Wes
@phpc @Crell proposed syntax: $gen = [for $list as $x if $x % 2 yield $x*2]; current php + short closures: $gen = () => foreach($list as $x) if($x % 2) yield $x * 2;
@bwoebi it's all your fault
and @LeviMorrison :B
 
I guess it depends whether you think of "locked" as adding functionality, or taking it away
will probably have to agree to disagree about declare
 
10:32 PM
So list comprehensions vs anonymous functions?
 
list comprehensions vs the absolute most minimal anonymous functions if we could make it work in the parser and didn't care about readability :P
 
hasn't () => been ruled out as impossible to combine with current syntax?
 
Wes
syntax is actually
$gen = (() => foreach($list as $x) if($x % 2) yield $x * 2)();
fn()=> was also good
 
right, so you're straw-manning a bit
I'm pretty sure all the proposals so far have required braces if the definition is more than an expression, too
$gen = (fn() =>{ foreach($list as $x) if($x % 2) yield $x * 2; })();
at which point it's no longer looking so pretty
unless we can make foreach an expression; but then that's pretty much what list comprehensions do
 
Wes
10:47 PM
i doubt [for ... ] is cleaner to implement than fn() =>
 
it's a lot prettier for this use case, though
 
Wes
it's a whole new syntax... we should generalize and make the current one less verbose, since it's basically the same...
 
it's a syntax for a special case, that's a lot shorter for that case than any generalised syntax could ever be
personally, I'm against short closures with both a full body and auto-capture anyway
they should be reserved for single-expression lambda-style cases
I don't want to end up having to debug nested scopes like in JS
 
Wes
don't blame the language for the programmer's sins
 
I'm not; I just like being able to look at a function and know the scope of all the variables
PHP has incredibly simple scoping rules, and auto-capture would shit all over them
 
Wes
10:56 PM
even if explicit? var $local; ?
 
so turn the current rules on their head? everything's pulled from outer scope unless declared locally? it would be better than guessing, but still a lot more complex than we have now
i.e. right now use $foo, global $bar, and static $baz are then only ways to import a variable from another scope
 
@IMSoP use
 
yes, as in function() use ($x) { return $x * 2; } - the use explicitly imports the variable; but some people want to be able to write () => { return $x * 2; } and have the variable magically imported
 
Wes
not from any scope recursively. not global. only within named functions
 
I'm on board with single expressions, like ($x) => $x * $y, because they're self-limiting
@Wes sure, but there's still no keyword telling you which variables are imported, and that's unlike anything anywhere else in PHP
also, they could be global, if the closure was defined globally; they could also be from another closure, if the closures were nested
 
11:02 PM
Honestly, I don't really see the point of use when the interpreter/compiler should be able to statically infer which variables are from the enclosed scope
(And screw variable variables, if you use those, you don't deserve nice things)
 
it's not for the compiler, it's for the programmer, that's my point
it's a design decision to say "functions have their own variable scope, and if you want to move something from one scope to another, you write it explicitly, and then everyone can see you doing it"
 
I can sorta see it, but on the other hand, I don't want to make it painful to do so.
 
if you're importing a whole bunch of variables, you're probably Doing It Wrong anyway
 
Wes
but it's not that you inherit variables from other files and third parties
it's your own code
 
JS is one extreme (implicitly take everything from every enclosing scope), PHP is another (gotta directly pass variables from outside scopes)
@IMSoP Not if you want to write in a functional style vOv
 
Wes
11:06 PM
@IMSoP i was waiting for this
 
surely a functional style would involve lots of explicit input and output, not lots of implicit scope?
 
C++ actually has a pretty good blend of explicitly passing closure variables, while keeping the syntax very concise.
 
Wes
classic "you are importing too many variables you are doing it wrong even if the only language i've ever used is php"
/me is off
bye
 
@IMSoP Currying/partial application/uplifting (promisification, collectionification, etc) becomes really painful if you need to explicitly declare everything
 
I mean, yeah, other languages do different stuff
 
11:07 PM
And use a specialized keyword to do it, too.
 
hm, I'm not sure why that would be, but I haven't experienced it enough to know
again, I'm talking about capturing more than a few variables, and defining a closure with more than one expression
 
@IMSoP It's not the capturing of more than a few variables that's painful
It's passing scope for more than a few layers down
It's the same blessing/curse as Java's checked exception
It's nice in theory, but now you have throws SomeException that you have to propagate through every single one of your layers.
 
I can sort of see that, I guess; but doesn't that still mostly come into the single expressions or other limited constructions space?
I guess I'm just not picturing the right examples
 
@IMSoP Not necessarily, a closure is often a single expression, but definitely not always.
Sometimes the mapping function you pass to array_map is much more complex than $x => $x * 2
 
absolutely; but when it is, you generally want that complexity to be readable
if there was a way to say "your closure must not be more complex than X to use auto-capture", I'd be happier
it's the idea of a 10-line callback referencing 8 different variables from 3 different scopes that scares me
 
11:16 PM
@IMSoP So, I've used lots of languages, and my current one is JS, where that is definitely possible, but in my experience, in practice, especially with CTRL+Click in the editor, it's really not a real problem in practice.
Like I said, as long as it's statically inferrable, it doesn't really matter.
Variable variable users can go suck on an egg.
 
yeah, I'm sure I'd get used to it; I just haven't yet seen the example that convinces me the tradeoff in readability is worth it
oh, I don't care about variable variables
 
@IMSoP And I claim that it's no less readable, I claim that use is noise
 
it's no more noise than naming function parameters
it's saying "the input to this function is these things"
 
@IMSoP Which sucks having to do that when working with anon functions a lot :(
 
again, I guess I just haven't seen the right examples
where the readability of an auto-captured block of more than one expression would win
it's actually something I found very frustrating with past short closure discussions: some of the examples made me want to barf
 
Wes
11:20 PM
@PeeHaa didn't they tell you to do this DUH?
$a = new stdclass;
$a->var1 = $var1;
$a->var2 = $var2;
$a->var3 = $var3;
function() use($a) // see, it's short now
{

}
 
@Wes What am I looking at?
:P
 
like $x => $y => $z => $x * $y + $z; that's not concise, it's line noise :P
 
Wes
the "if you need to import a lot of variables put them in an object" advice™
 
It sucks having to manually import the things I actually want/need
Especially when the scope it is in is tiny and it's easy to manage what is coming from where
@Wes Still the same useless typing to get the stuff I want
Hell even more typing and boilerplate :D
 
Wes
@PeeHaa yeah it was a joke :P
indeed it's even more typing
 
11:24 PM
I am never sure with you and scared to ask :D
 
Wes
ahah
 
I still love you though
 
Wes
i love you too
 
\<3/
 
@PeeHaa meh, it seems fine to me; no more boilerplate than having to write local $socket to force the scope the other way
 
11:25 PM
I don't need local
 
I know, because PHP assumes it :P
 
Exactly
 
I just meant, in some languages, you would
 
@IMSoP It may seem fine, but again. I write that a lot
 
Wes
imho use() is clumsy to write:
function() use{
    $a3sjdf93isdfj,
    $sdf023jdjisf,
    $sdf3a3sjdf93isdfj,
    $dsf92sdjfa3sjdf93isdfj,
): MyClass{


}
 
11:27 PM
yeah, I'd kind of prefer it inside the function block
 
Basically everywhere where I have a generator which I need to turn into a promise
 
Wes
is much harder to write than this:
function(): MyClass{

    nonlocal $a3sjdf93isdfj;
    nonlocal $sdf023jdjisf;
    nonlocal $sdf3a3sjdf93isdfj;
    nonlocal $dsf92sdjfa3sjdf93isdfj;


}
 
function(): MyClass{
    capture $a3sjdf93isdfj,
    $sdf023jdjisf,
    $sdf3a3sjdf93isdfj,
    $dsf92sdjfa3sjdf93isdfj;

}
 
Wes
it's the parentheses, the return and the braces that make it especially annoying
 
yeah, the syntax is definitely non-ideal
it's more the semantics of "must import all non-locals" that I'm defending
 
11:29 PM
Just have sane and clean scopes to begin with and there is no problem
Otherwise you are going to shoot yourself in your foot, buuut you are going to do that regardless in that case
 
Yes, but let people shoot themselves in their foot instead of making it harder for me
 
@IMSoP Eh, like I said, in my experience, in practice, in JS, which is the opposite extreme (every scope has access to all enclosing scopes implicitly), it's not a huge problem in decent codebases.
You can do abominations, sure, but PHP is the king, queen, and god of abominations.
 
yeah, and scope ain't one of them, so let's not add it ;)
but sure, maybe I'm worrying too much
it would definitely be nice to have short lambdas
and if people use short closure blocks responsibly, they could be nice too
it'll just take a bit of getting used to, that you can't trust your scopes on sight any more
 
Wes
@MadaraUchiha should inherit from within named functions only
which means that variables will be shared only within closures that are in the same file
 
11:34 PM
@Wes $f = $x => $y => $x + $y ?
 
Wes
named as in function bar(){ /* */ } or class Baz{ function bar(){ /* */ } }
 
@Wes if you just mean blocking global scope, that's only half the battle; the main problem is function() { .... function () { .... function () { ...
definitely a coding style violation rather than a language one, but right now it's one the language doesn't even let you get close to
anyhow, I should really be in bed already
 
Wes
unless you have hundreds of lines long functions and not have a solid idea of what the variables in play are, you won't accidentally use the wrong variables
 
yeah, as I say, I may be worrying too much; I've seen some pretty awful JS code, and the nested scope felt like part of the problem, but probably I'd get used to, and coding standards would adapt to it
it still feels like a tradeoff compared to our current simplicity, though, and I'd love to see better examples next time a short closures RFC comes round
 
Wes
imagine if we required control structures to import variables....
foreach($bar as $baz) use($bar){}
that's the struggle so many people fail to understand.... it's the same thing
 
11:43 PM
sort of; except you can't store the foreach loop, pass it around, and find you've got a reference to a bunch of objects that you thought had been destructed half an hour ago, or whatever
control structures are mostly glorified gotos
particularly in PHP, where they don't have any local scope either
 
Wes
the scope is not shared with "around"... as in, it's lexical :P the code is all in the same place, third parties can only decide when to execute it
 
@IMSoP If all you've seen is nested code... you haven't seen awful JS code.
 
lol
 
When PHP code looks bad, you want to kill someone. When JS code looks bad, you want to kill yourself.
Casual PHP code generally looks worse than casual JS code, in my opinion
But job security PHP code vs job security JS code? There's no comparison.
 
Wes
lol
 
11:49 PM
The things I've seen....
I still wake up in the middle of the night in cold sweat, on occasion...
 
right, I'm really going to have to go to bed; thanks for the patience, all, I promise I was listening
 
"No! Don't use that prototype!"
 
@IMSoP night o/
 
😃 Same.
 
Wes
gn. sorry if i was mean
 
11:50 PM
🌔 🌠 night
 
:)
 
@MadaraUchiha but which way?
 
@Danack JS is orders of magnitude worse.
The shit I can pull off with lexical scope alone, (not to mention this and __proto__ shenanigans) is enough to fuel nightmares.
Consider that in JavaScript, (""+[][[]])[[]] is a valid piece of code that returns "u".
I'll let you guys figure out how the hell that works :D
 
@MadaraUchiha undefined
 
Wes
i have no idea why people can't leave "this" alone
 
11:56 PM
@Wes Consider this
 
Wes
it's like js allows is so it's fine doing it all the time
we use a script on a site i maintain i don't dare to touch... there are hundreds of apply()
 
class MyButton {
  constructor(btn) {
    this.btn = btn;
    this.x = 42;
  }

  attach() {
    this.btn.addEventListener('click', this.handleClick);
  }

  click() {
    console.log(this.x);
  }
}

const someBtn = document.getElementById('someBtn');
const myBtn = new MyButton(someBtn);
myBtn.attach();

// What is the expected output when clicking someBtn now?
 
42 in console?
 
@Tiffany You'd think that.
In reality, you get undefined.
The reason for that is that this is determined at the callsite, not at the function declaration
 
Wes
yes it's also js's fault
 
11:59 PM
this.handleClick is simply a reference to a function
The callsite is inside whatever scope that clicks the button in the browser code
 
Wes
this.handleClick doesn't carry this, unless this.handleClick.bind(this)
 

« first day (3067 days earlier)      last day (1895 days later) »