« first day (1752 days earlier)      last day (3189 days later) » 

2:01 PM
How about foo(function(SomeClass $o /* plus any method args */) { $o->instanceMethod(); }); @Danack?
Horrible in other ways, but at least solves that specific problem
 
@DaveRandom That's so horrible, we should put it in PHP core /cc @Trowski
 
Morning, room.
 
mornin
 
@Abe Not really:
 
user895378
2:12 PM
@LeviMorrison o/
 
$iterator = new SomeIterator();
$iterator->valid(); // undefined behavior
 
Anonymous
Afternoon o/
 
@rdlowrey I have some bad news.
Leviathon has moved into the basement.
 
user895378
lol
 
ETA on cable running is undetermined.
 
user895378
2:13 PM
no worries
 
Abe
@LeviMorrison undefined behavior is even more odder :P
 
@Abe You need to call rewind() before anything else.
But not in the constructor.
If you do rewind() in a constructor make sure that another call to rewind() will be harmless.
 
Abe
but that's just because of foreach(), right? because it is way too counterintuitive
i mean, it looks more normal assuming that a newly created iterator is rewound already
 
Does anyone have any reference on how to get TwigServiceProvider working with SecurityServiceProvider in silex?
 
@Abe It's just how it was designed.
I'm not saying it was a good choice.
 
Abe
2:20 PM
@LeviMorrison i don't think it was designed like at all :P i mean, the Iterator page on php.net doesn't say anything about how it should be implemented
 
@Abe Documentation sucks :)
@Abe Note that it is sort of documented here: php.net/manual/en/iterator.valid.php
> This method is called after Iterator::rewind() and Iterator::next() to check if the current position is valid.
 
Abe
that's odd too, because sort of assumes you can only use such methods automatically via foreach()
should be like $iterator->isRewound() ? $iterator->rewind()
 
Again, I'm not saying it's a good design.
It's just the design that is there.
 
Abe
but that's not even necessary since a second rewind() call could just do nothing
 
@Abe Not all iterators can be rewound, FYI.
 
Abe
2:28 PM
then rewind() shouldn't be part of the interface :D
 
1 min ago, by Levi Morrison
Again, I'm not saying it's a good design.
 
Abe
ahahah
tbh it's not that bad @LeviMorrison definitely not the worst design you can find in php
or better, spl. it's one of the very few things i would save of spl :P
 
Iterators are better designed than many other parts of the SPL.
 
Abe
maybe it's a bit too verbose. could have been simpler, like java iterators for instance
 
(Disclosure: my work)
 
Abe
2:31 PM
yep @LeviMorrison i'm Worf. i change nick frequenty to annoy @PeeHaa :D
 
Oh. Hello, @Worf. :D
 
user895378
haha
 
Abe
i literally reverse-engineered everything in ardent. and learned lot of things :D
 
As good as Ardent is I still don't think it's all that great.
Plenty of work to do design wise.
 
Abe
i know, but i loved the effort
 
2:33 PM
I think I'll actually go work on stuff right now.
I have some spare time but not enough to chew off anything big.
It's been a while since I had spare time.
 
@bwoebi phpdbg exceptions_001.phpt will end up running HANDLE_EXCEPTION with opline_before_exception = NULL. That does not seem right
 
@Abe No problem. With my Wes Finder ™ I can find you whatever your name
 
@Danack So what's going on there?
 
Abe
@LeviMorrison i know. i try to spend all my free time working on my personal stuff too, but it's hard doing actual thinking with huge holes of hours that are spent for my actual job
even weekends aren't enough :(
 
morning, @Trowski o/
 
2:37 PM
I just updated to PhpStorm 9. Hooray for return types not borking the whole file!
 
Morning @kelunik \o
 
@Trowski Short version, there's no way to express that the a callable to be called is an instance method of a class, without passing an instance of that class around. DaveRandom's workaround of creating an anonymous function to express that works, but is a pain in the butt.
As it requires typing out code, and who likes doing that.
 
Well, the underlying problem is that the function does not require a callable, it simply requires something from which the injector can infer a callable. Using a callable typehint does not adequately describe the range of permissible values.
 
If that's not complete insanity, it could fit within your hypothetical callable RFC.
 
@Danack An instance method isn't going to be callable without an instance, so I'm not sure how that would work.
You'd have to provide an instance at call time.
 
2:44 PM
@DaveRandom That's one way of putting it. The other way is that it's too hard to express instance methods as things that could be callable.
43 mins ago, by DaveRandom
How about foo(function(SomeClass $o /* plus any method args */) { $o->instanceMethod(); }); @Danack?
i.e. if callable($classname, $instanceMethodName); returned that closure, it would pass the callable check.
 
Abe
@LeviMorrison i could barely notice the differences with phpstorm 8. felt disappointed. and still no php 5.6 full support
 
@NikiC You have a case where that goes wrong? … Well, maybe it could be an issue if you break on ZEND_HANDLE_EXCEPTION opcode?
 
@Abe Bugs are filed though, so perhaps for PhpStorm 10.
Still better than any other IDE for PHP I've used.
 
@Danack That is essentially what I'd like to see from callable($classname, $instanceMethodName);
 
@Abe Yes, some annoying bugs I reported have only been fixed after the release, they'll be included in 9.0.1 or 9.0.2
 
2:48 PM
So, it sounds like I've missed some important callable discussion?
 
@bwoebi It happens with the exceptions_001.phpt testcase from phpdbg
 
Abe
that's for sure. but other languages' IDEs don't have such problems @LeviMorrison
 
@bwoebi Ah, it doesn't go wrong currently - because the result opnum is too large to accidentially be valid
But it goes wrong when someone actually tries to use the opline
 
Abe
@kelunik functions recognized as classes? i believe that will only be available in 10
 
@LeviMorrison trowski is thinking of making a internal function callable() to allow generation of closures to make things be actually callable, not sure if he has written stuff down yet.
 
2:50 PM
@Abe It's fixed, but they introduced another bug. Now all non-imported functions are classes, lol.
 
@Danack Oh, roughly the same idea that @Andrea and I were tossing around then.
 
@LeviMorrison I have a draft of an RFC (which apparently I need to completely re-write as people didn't grok it), to make the behaviour of callable be sane: gist.github.com/Danack/59f8104ef2aaaa9b2256
 
Abe
@kelunik how did you feel when you noticed that they fixed the bug the day after they released phpstorm 9? xD (╯°□°)╯︵ ┻━┻
 
as currently I don't believe it is e.g. private methods on an instance pass the callable test.
 
2:51 PM
I didn't pursue it because I believe the better route is unifying class properties/methods/constants. I'd like to at least attempt that first.
 
@NikiC correct ;-D … yeah, I need to backup that one too.
 
@nikiC How difficult would it be in fast route to add additional values associated with route a that array merged with the dynamic route vars?
 
I realize there is a good chance it would not pass.
 
@Abe Yeah, just like that, but I was too lazy to install a new EAP. youtrack.jetbrains.com/issue/WI-27571 is another one they fixed shortly after the release.
 
@Orangepill E_ENGIRSH :P
 
2:53 PM
@LeviMorrison I don't see how they're linked?
 
@Danack Once they are unified then Countable::count can reference the method.
 
$r->addRoute("GET", "/images/thumbnails/{imagefile}.jpg", "imageResize", ["target_width"=>75, "target_height"=>75]);
$r->addRoute("GET", "/images/medium/{imagefile}.jpg", "imageResize", ["target_width"=>150, "target_height"=>150])
 
There's no need for a function to make a callable.
 
@peehaa ^ like that
 
user895378
@Orangepill I see no reason for that
 
2:54 PM
@Orangepill huh?
 
then returned vars would contain a target_width and target_height element
 
If you need that wrap it and attach the data yourself I would say. Although it looks strange
 
Oh, ok I see - to allow the syntax to be interpreted unambiguously.
 
user895378
$r->addRoute("GET", "/images/medium/{imagefile}.jpg", $data);
// then after routing:
list($function, $extraStuff) = $routingResult;
 
@rdlowrey ohh i see
 
user895378
2:55 PM
the route target doesn't have to be a callable
 
@Danack Well… it's technically not ambiguous right now because we made rules such that certain syntax is for constants, properties and methods.
But I think you get what I mean.
 
yep.
 
I realize there is a good chance it wouldn't pass.
I do think it would be the best option once the dust is settled, so to speak.
 
user895378
> allow the syntax to be interpreted unambiguously.
 
user895378
lol yeah ... um ... this is PHP
 
2:58 PM
:D
@Abe So more like:
interface Sequence {

    /**
     * Returning null indicates the sequence is over
     * @return mixed|null
     */
    function next();

}
 
@LeviMorrison This is a bad API
If you want to keep it to one method, use an exception to signal the end of the iterator
 
@NikiC Aside from the inability to hold nulls, why do you think that?
Really? An exception?
 
@NikiC That's a bad API then...
 
@LeviMorrison It's the standard solution to avoid the null problem
 
Just do a Maybe
Then you can have a Something that holds null
 
3:03 PM
If a Maybe is available, that's indeed preferable
 
Exception is definitely not better imo.
interface Sequence<T> {
    function next(): Maybe<T>;
}
I'm still not sure in a language like PHP generics would work without significantly added complexity.
But if we had them then something like that would work nicely.
 
Generics never work without significantly added complexity ^^
 
@rdlowrey thanks for opening my eyes ... that is an eloquently simple solution to all the perceived shortcomings of fastroute
 
user895378
Yeah, fastroute doesn't have shortcomings ;)
 
3:09 PM
:D
 
USB usb = ...;
if(usb != null && "3.0".equals(usb.getVersion())){
  System.out.println("ok");
}

Optional<USB> maybeUSB = ...;
maybeUSB.filter(usb -> "3.0".equals(usb.getVersion())
                    .ifPresent(() -> System.out.println("ok"));
I can't say optionals in Java make code more readable. ^^
 
@rdlowrey I see that now...
 
@LeviMorrison I was thinking it would be a language construct that would create a callable, including creating a callable to a protected/private method if you were within the class context.
 
mus
hello all
can someone help me?
 
@Trowski You mean one that can call the protected/private method outside of class scope?
 
mus
3:15 PM
none?
ok bye
 
@LeviMorrison Yes.
 
@NikiC But thanks for heads up, fixed :-)
 
@bwoebi wow, that was quick :)
 
@NikiC 20 min isn't that fast.
 
@LeviMorrison The usage for that is somewhat limited, but I have written a few classes that could benefit (and I believe so has @rdlowrey).
 
3:20 PM
@Trowski Oh, I have too.
 
user895378
@LeviMorrison Yeah, that's the main use case
 
user895378
To be able to pass private callables out to things that require callbacks
 
user895378
Currently I just use reflection with a getClosure() call
 
Eh, it's uncommon enough that I think I'd vote in favor of just writing a closure.
 
@rdlowrey I usually just write a closure function (...$args) { $this->method(...$args); };
 
user895378
3:21 PM
@LeviMorrison well, in performance contexts the overhead of instantiating a new closure and doubling the number of fcalls is a drawback
 
@Trowski Yeah, that's the same thing I do.
 
user895378
But I don't think it's really necessary to add the functionality to the language.
 
user895378
If I have something like that AND performance really matters I just use reflection one time at the beginning of the application and create it.
 
@rdlowrey How do you want to do that without being part of the language?
 
@rdlowrey I would like to see it, but it's not exactly at the top of my todo list since there's an easy workaround.
 
user895378
3:23 PM
@kelunik I just use reflection?
 
@NikiC Why is that a bad API?
 
bah bah
dammit, umask()
 
yeah
 
@Danack Without an explicit instance, from the engine's point of view it isn't callable. You're looking at it from the PoV of the userland application, not what it means to the engine. It doesn't make sense for the engine to consider that as anything other than an attempt to call an instance method statically
(IMHO)
 
@Danack how does Imagick internally create files? Do you just call the CLI command, even in windows environments?
 
3:30 PM
@DaveRandom Not disagreeing, just want to be able to pass that information around in a way that isn't open to having typos.
@Ocramius Imagick uses the C api into ImageMagick - imagemagick.org/api/magick-image.php
 
Agreed, but I can't see a way to do it without some kind of user-defined type system, which is not viable in about a million different ways
 
@Danack thanks :)
 
There is some stuff in the CLI that isn't exposed through the API.
 
Yeash, was wondering whether you were going through the tty again or if it was doing all in memory
 
@Fabor Vomiting?
 
3:33 PM
Wut?
 
@bwoebi because null
 
@NikiC that doesn't make a bad API of it. It's just one way to design the API. It's not particularly bad. It's just once choice of many.
 
user895378
Bob is the king of type|null returns :)
 
@bwoebi No, it's bad.
 
user895378
@bwoebi FWIW I agree with @NikiC on this.
 
user895378
3:35 PM
I don't think mixed|null returns are a good idea
 
Why?
 
@NikiC Throwing at the end of a sequence seems wrong. It's expected, not exceptional at all.
 
If you're building a generic API, you can't have a null ambiguity
@Trowski Sure, it's wrong, it's just the standard solution to this problem for languages that don't have Maybe/Optional
 
yeah, but here we have no ambiguity.
 
user895378
What if I want to have null in my sequence?
 
3:36 PM
@rdlowrey That's why iterators have a valid() method as well.
 
user895378
@Trowski I'm operating under the "one method assumption"
 
user895378
35 mins ago, by NikiC
If you want to keep it to one method, use an exception to signal the end of the iterator
 
@rdlowrey Then throwing would be really the only option.
 
@rdlowrey then it's obviosly a bad choice.
 
user895378
I have a constant tension between correctness and robustness ...
 
user895378
3:38 PM
I don't love exceptions ... in particular if you have long-running programs.
 
user895378
They make writing programs that can't afford spurious crashes much more difficult.
 
Let's actually do some packed string benchmarks, Andrea
Hmm...
 
Moar shoulder elephpants!
 
@rdlowrey Same. I have a few methods without a return type because I return null instead of throwing.
 
@Fabor The question is, is that the good elephpant or the bad elephpant on @Andrea's shoulder?
 
3:39 PM
Hello. It's my first time here and I'm not sure if this would be a good question for the main site. I have some HTML knowledge and know some PHP and, while trying to build an Userscript, I need to find the PHP or HTML event that I need to modify. The question would be how to find that part in a complex file - it's probably hidden in some javascript. And maybe there's a better room for that, then? - Is this an ok question for main?
 
@rdlowrey exceptions are but one tool, and not always the correct one
 
I'm conflicted on those because it seems correct to return null because it's expected, but I hate not being able to be explicit.
 
Abe
@LeviMorrison how do you believe/hope/pray arrays should work in future php releases? should they be passed by value like it is now?
 
Haskell, which unlike PHP was carefully designed, uses both optionals (Maybe type) and exceptions to handle errors
 
@NikiC What makes it a bad or good elephpant?
 
3:40 PM
@NikiC D:
Well, it's Sara. So bad, obviously :p
 
@Abe Eh, I'd prefer they acted like objects. I really don't think that would ever pass.
 
@Trowski Eh, I wouldn't use exceptions just to get that extra typehint in...
 
Changing array semantics like that would probably break ~100% of PHP programs.
 
@LeviMorrison I like being able to have stuff pass-by-value
 
@Andrea From what I heard from people who actually use Haskell non-trivially, it isn't all that well designed.
 
3:41 PM
@Zachiel it wouldn't be a great question, as it's too specific to your code. And a more general question of "How do I debug stuff" is also a bad fit, as it's too broad.
 
I'd love pass-by-value classes....
 
@Andrea Oh yeah, obviously ^^
 
@Andrea Structs.
 
@NikiC its goals may not necessarily align with those of its users
 
@NikiC There might be nullable types in the future too.
 
3:42 PM
@Zachiel It might be a better fit for programmers.stackexchange.com - but not guaranteed to be.
 
@LeviMorrison Yes. Change the keyword to struct in the declaration and it could be pass-by-value. I'd love that
 
@Trowski yeah, that'll solve it
 
Abe
@LeviMorrison :(
 
user895378
/me still wants tuples
 
(and it'd enrage Dmitry)
@rdlowrey write a class!
 
user895378
3:42 PM
@Andrea yes, incur like 10 fcalls and an object instantiation to achieve immutability
 
user895378
:(
 
@rdlowrey No, just one
 
user895378
A tuple with one element is a scalar
 
@Danack I see. Any idea about where I could find some help, apart from programmers.se? I found one of the two elements that change in the precise moment I want to start (an icon changing when I get mail) but I just see the element and can't find where it is that the images are actually changed...
 
I would really like to be able to have an array of a type, i.e. SomeClass[]
 
3:43 PM
@rdlowrey Hrm, I read that as 10 fcalls to achieve immortality
4
 
@rdlowrey objects are quite lightweight...
 
user895378
@Andrea yes, but the fcalls aren't.
 
And objects aren't lightweight either ^^
 
user895378
well, my experience from a perf standpoint is that new stdclass isn't very harmful relative to other things
 
3:45 PM
@NikiC they are quite lightweight.
 
@rdlowrey ONE fcall.
 
user895378
@Andrea not if you want to access it by index
 
btw those were found with "chrome detect dom change"
 
@rdlowrey one fcall per indexing operation
 
user895378
@Andrea yes, which matters greatly if you want immutability to be a prominent feature in your application
 
user895378
3:46 PM
one fcall doesn't matter.
 
user895378
It's the compound interest of having to make that one fcall frequently throughout the program.
 
@rdlowrey I don't see a difference between reflection and an anon function:
anon function: 2.260884
reflection:    2.220158
anon function: 2.276921
reflection:    2.248755
Well, slightly.
 
@rdlowrey if you want immutability, you could use arrays.
 
What exactly are you testing? @kelunik
 
user895378
@Andrea by-value is not the same as immutable
 
3:47 PM
@rdlowrey well, yes, but it's close. By-value is the PHP way ^^
 
user895378
@Andrea this is true.
 
@bwoebi RespParser with both methods, but yeah, most time is spent on parsing there. ^^
 
It lets you do imperative operations, but the side-effects are relatively controlled
 
@kelunik I'm surprised reflection is that close. Was much slower when I benchmarked it, how did you test that?
 
user895378
maybe tuples just aren't really necessary when we have the smorgasbord of PHP arrays :)
 
3:48 PM
You can't mutate an array at a distance if the field is readonly
 
user895378
@kelunik can we see the actual benchmark code?
 
@kelunik yeah okay, that's not a good benchmark :-P
 
@bwoebi yeah :P
 
user895378
I'll put together a bench ...
 
Anonymous
Is there any way to check if value is an instance of, say ... a function? Not that functions have instance like objects .. but just wandering :/
 
3:50 PM
@samaYo what do you mean by "an instance of a function"?
 
@samaYo is_callable(), or you can use instanceof \Closure if you specifically want an anonymous function.
 
Anonymous
set_exception_handler(function($e){
    var_dump($e instanceof \Exception);
});

throw new \Exception;
 
Anonymous
@Andrea ^ , but for a function ..
 
Abe
@samaYo is_callable ?
or $x instanceof Closure if you want closures only
 
Anonymous
yeah, got it.
 
3:52 PM
I think I figured out the function referencing thing better, by the way
I wanted to allow you to have Closure be unbound. No. Bad.
Make a separate class: UnboundClosure or something, which you can't call until you bind it, which converts it into a Closure
So, the hypothetical $foobar = callable(Foo::Bar);, where Foo::Bar is an instance method, would give you an UnboundClosure
 
You could then do $foobar->call($fooInstance);, or $foobar = $foobar->bind($fooInstance); $foobar();
 
user895378
@kelunik in my tests the closure looks to take about 2x the time as the reflection approach
 
user895378
(which makes sense because it's two fcalls vs one)
 
The weird thing is: That things is now slower than with the actual parsing code, lol.
 
3:55 PM
@kelunik I would be interested in the time taken to create the callable. Reflection isn't cheap.
 
@kelunik Amp\run()? lol :-D
 
user895378
@kelunik just posted my benchmark code as a comment
 
@Trowski It's not in there and it doesn't matter, it could take forever.
 
If you're going to reuse the same callable over and over, reflection is probably better. If it's single use, then the closure is probably faster.
 
Deadpool teaser trailer out :).
 
user895378
3:57 PM
Yeah, I only ever use reflection one time in the bootstrap phase. It makes no sense to repeatedly reflect during runtime
 
Oh Mr. Reynolds <3 the only man who can replace Daniel in my heart.
 
Also
Who needs a special operator? Just unify the namespaces. Well, you can't "just" do that. If a constant lookup fails, look for a function.
 
anon function: 0.071181
reflection:    0.046289
 
@Andrea I feel like clarity needs one
 
Yeah, executed the old file instead of the new one. ^^
 
3:58 PM
array_map(strlen, ["foo", "foobar", "elePHPant"]);
@NikiC well, it might confuse people reading, yeah :/
 
If you just see $foo->bar in the code and you don't know whether that's the property $foo->bar or a closure for the method $foo->bar() that's likely not good
 

« first day (1752 days earlier)      last day (3189 days later) »