« first day (1682 days earlier)      last day (3256 days later) » 

12:50 AM
@bwoebi you were right about classes naturally popping up if you have functions with shared state! I had a bunch of spider functions passing around the same three values, so I made them into a class.
 
@Andrea exactly… And by that you maybe don't have the cleanest design yet, but you already know what's related and grouped in simple classes.
 
Yeah.
 
Any developers got skype?
 
Also meant I got rid of a reference.
 
> Namespaced assert
A call to assert(), without a fully qualified namespace will call assert in the current namespace, if the function exists. An unqualified call to assert is subject to the same optimization configured by zend.assertions.
Calling \assert() will always invoke the system function.
that's great
 
12:59 AM
Gosh
 
it isn't? :D
 
No I mean
I really wish the function __construct(string $this->name, int $this->age) thing got in
 
ah yeah that was cool too
 
but it didn't
:(
class Opcode
{
    private $lineNumber;
    private $type;
    private $operand1;
    private $operand2;
    private $result;

    public function __construct(
        int $lineNumber,
        int $type,
        Operand $operand1 = NULL,
        Operand $operand2 = NULL,
        Operand $result = NULL
    ) {
        $this->lineNumber = $lineNumber;
        $this->type = $type;
        $this->operand1 = $operand1;
        $this->operand2 = $operand2;
        $this->result = $result;
    }
All my classes look like this.
 
Refactored a (goto based) incremental HTTP parser out from a class into a single Generator! Saved more than 1/3 of the LoC!
 
1:01 AM
did a poll actually happpen?
 
@Worf think so
 
@Andrea no, it didn't I believe
 
class Opcode
{
    private $lineNumber;
    private $type;
    private $operand1;
    private $operand2;
    private $result;

    public function __construct(
        int $this->lineNumber,
        int $this->type,
        Operand $this->operand1 = NULL,
        Operand $this->operand2 = NULL,
        Operand $this->result = NULL
    ) {
    }
 
@bwoebi Oh, hmm...
 
1:02 AM
^ hehe, I replied to a message coming after mine :-D
 
shame
oh, actually, you could write a function to do it for you
initialiseProperties($this, func_get_args());
Almost tempted to do so.
Almost.
 
why do you pass $this?… let debug_backtrace() figure that out :-D
 
@bwoebi noooooo
 
lol
 
Now, the fun part
 
1:05 AM
@Andrea you anyway need reflection to get the variable names
 
You can have initialiseProperties set your private properties!
 
private $lineNumber, $type, $operand1, $operand2, $result;
maybe? not a fan tho :P
 
@Worf My complaint isn't line count, it's having to type it out so many times
I have to type each variable name FOUR TIMES
 
eheh
was trying to understand why that was declined
i mean, it would have done no harm to the language "purists"
added the quotes
 
> Depending on the scope, get_class_vars() will only return the properties that can be accessed from the current scope.
What MONSTER did this
IMPLICIT STATE
WHYYYYYY
 
1:12 AM
hehehe
get_defined_vars() ftw
 
anybody use PHP Storm?
 
most of us do, yeah
 
I just got it. I downloaded the student/teacher edition. that's really awesome they do that for students and teachers.
 
function setPropertiesFromArguments($self, array $arguments) {
    // use evil magic to set ALL properties!
    $evilMagic = function (array $arguments)) {
        $i = 0;
        foreach (get_object_vars($this) as $name => $value) {
            $this->$name = $arguments[$i++];
        }
    };
    $evilMagic->call($self, $arguments);
}
More evil magic.
I really am diabolical.
I just wondered if diabolical is related to diablo. Yep. Same root.
"Devilish", literally.
 
i believe it's diabolic, not diabolical. considering the latin root of the word :P
nvm. xD
languages are weird.
 
1:18 AM
Both are correct!
 
what's a good Keymap Scheme to use?
 
function initProps() {
    $bt = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT)[1];
    $class = new ReflectionClass($bt["object"]);
    foreach ($class->getConstructor()->getParameters() as $i => $param) {
        if ($class->hasProperty($param->getName())) {
            $prop = $class->getProperty($param->getName());
            $prop->setAccessible(1);
            $prop->setValue($bt["object"], array_key_exists($i, $bt["args"]) ? $bt["args"][$i] : $param->getDefaultValue());
        }
    }
That's how I imagined it :>
 
OMG it worked
 
sure, it works.
 
1:20 AM
@bwoebi yes, that's the proper way to do it
 
@Andrea but your solution does not respect optional params :-P
 
This is true!
 
$limit to debug_backtrace or it will kill your app (learned the hard way)
btw would be great to have $exc->getTrace($limit) as well
 
@Worf $exc being a ReflectionGenerator?
 
Exception?
 
1:22 AM
ah
^^
 
debug_backtrace(..., $limit = 2);
$exception->getTrace($limit = 2);
 
> debug_backtrace
What is this sorcercy
 
magic!
 
Worse.
 
black magic!
 
1:24 AM
Yes.
@LeviMorrison Are you going to chastise us?
 
with the uniform variable syntax fix i went full oop
return $searchSequence->getLength()() > $this->getLength()() ? yes() : no();
god i love doing nasty fun stuff with php xD
 
Shame on all of you.
 
lol
 
Why am I chastising you this time? :)
 
@LeviMorrison Scroll up?
function setPropertiesFromArguments($self, array $arguments) {
    // use evil magic to set ALL properties!
    $evilMagic = function (array $arguments) {
        $vars = get_object_vars($this);
        foreach ($arguments as $value) {
            $this->{key($vars)} = $value;
            next($vars);
        }
    };
    $evilMagic->call($self, $arguments);
}
improved my version, @bwoebi
Now it works properly for optional params ;)
 
1:30 AM
function initProps() {
    $bt = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 2)[1];
    foreach ((new ReflectionClass($bt["object"]))->getConstructor()->getParameters() as $i => $param) {
        (function() use ($param, $i, $bt) {
            array_keys(get_object_vars($this))[$param->getName()] && $this->{$param->getName()} = array_key_exists($i, $bt["args"]) ? $bt["args"][$i] : $param->getDefaultValue();
        })->call($bt["object"]);
    }
}
 
...
 
@Andrea Shame on you for using array type when probably any iterable thing would do
 
@LeviMorrison ...wat
setPropertiesFromArguments($this, func_get_args());
is the use case
Hmm
I think I'll just not use this shortcut.
@bwoebi's solution would work perfectly, but it uses Reflection!
 
@Andrea haha
 
My solution doesn't handle optional arguments
 
1:34 AM
because func_get_args() doesn't return them, yea
 
But I like that it doesn't use reflection, see
I don't really know why I care
It's more fun to do things without using reflection
Reflection is kind of like cheating
 
hihihi
 
There's a few reflection-esque functions lying about. Like get_object_vars etc.
 
yeah
 
i imagine one day to have function/class objects and be represented by reflection. like
class Bar{}
Bar->newInstance()
Bar instanceof Class // true
function(){} instanceof Function // true
if you put it this way, reflection looks less hackish
 
1:39 AM
guys can someone please help me?
0
Q: Decode Base64 image from MySQL server

Yohan BlakeI am storing my image as BLOB in an online MySQL database by encoding the image using Base64. I don't have a problem with saving. But I can't retrieve the images from the server. They appear to be broken. I believe this is happening because it's not being decoded. I tried manually uploading a c...

 
@YohanBlake search for a PDO tutorial. php.net/PDO
 
thanks, but what am I doing wrong in my code?
 
what does the image column contains in your database table?
the path to the image? or the image binary data itself
 
I keep using classes where what I really want is a module
@ircmaxell
Like, it's not an object. It's a function with a defined input and output.
But that function is complex and needs to call many sub-functions
 
Can we please throw a notice when unset()'ting a variable?
 
1:44 AM
@bwoebi ...what?!
 
I mean undefined index etc. when the variable doesn't exist
 
... a variable that didn't existed?
 
@bwoebi Ah, okay
 
not on the variable itself, but in between
 
i like it retuning bool better @bwoebi
 
1:45 AM
e.g. unset($this->var["foo"]) … when $this->var doesn't exist, please a notice…
 
unset($this->var['foo']) || catapult(new Error('Unsetting an array key that didn't exist'));
in case you forgot:
May 20 at 21:11, by Worf
/me **polyfills**
function catapult(Exception $e){ throw $e; }
isset($x) || catapult(new Exception);
 
:-D
 
@Worf isn't using or more idiomatic?
 
yeah i believe the notice would break stuff, having it returning a boolean is cool instead. i'd use that in several places instead of using array_key_exists or isset
@Andrea probably, but i only remember the || && operator precedence :P so i always use that. i couldn't ever memorize the difference between or and || and && and and
wow this is great. or and || and && and and
 
@Worf the point of or and and is they have lower precedence
so you can do $foo = bar() or die(); and it won't assign the result of die(); to $foo
Another way to put it:
($foo = bar()) or die();
$foo = (bar() || die());
of course the result of die() doesn't matter, but still.
 
1:52 AM
i see. that helps
tbh i am always very specific with ambiguous-ish logic expressions. you would never see stuff like $a || $b && $c in my code, i always wrap them into parentheses
so that it can't be ambiguous at all
 
Yeah
I've struggled with their precedence, so I just never assume it
if (substr(OPCODE_NAMES[$opcode->getType()], 0, 8) === 'ZEND_JMP') {
I am breaking so many rules
 
lol
is that php?
 
Yes.
 
OPCODE_NAMES is an array? :|
 
150
A: PHP Constants Containing Arrays?

AndreaSince PHP 5.6, you can just do this: <?php const DEFAULT_ROLES = array('guy', 'development team'); Or even: <?php const DEFAULT_ROLES = ['guy', 'development team'];

 
2:00 AM
woaaaaaaaaaaaaooaaoaooaoooo. didn't know that
 
It wasn't really publicised
 
will abuse it from now on :D
 
Do! :D
warning: I don't think isset likes constant arrays (maybe it does in 7? not sure, certainly doesn't like them in 5.6)
have to use the proper function
 
proper function?
array_key_exists ?
 
(function () {
    "use strict";
    // opcode ZEND_NOP wuz here
    // opcode ZEND_INIT_FCALL wuz here
    // opcode ZEND_SEND_VAL wuz here
    // opcode ZEND_DO_FCALL wuz here
    // opcode ZEND_ECHO wuz here
    // opcode ZEND_RETURN wuz here
    function factorial () {
        var jump = 0;
        goto_emulation:
        while (true) {
            switch (jump) {
                // opcode ZEND_RECV wuz here
                // opcode ZEND_IS_SMALLER wuz here
                case 2:
                // opcode ZEND_JMPZ wuz here
...progress!
@Worf Yep
 
2:16 AM
@Andrea How I made Andrea earn 150 upvotes…
 
^^
 
@Andrea J... J... Java…script!?!!?!
 
Yus! :3
 
@Andrea if it doesn't, then it's a bug… did you report it?
 
Not in HHVM, tho. lolhhvm
When PHP 7 comes out we can laugh at HHVM's awful PHP 7 support. Then cry when nobody uses PHP 7 features for that reason. ;_;
 
2:19 AM
haha
Poor Sara (:-D)
 
function getEndsWithSeq($searchSequence){
	expecting(Sequence)->check($searchSequence);
	if($searchSequence->getLength()() > $this->getLength()())
		return no();
	$ii = $this->getLength()->sub($searchSequence->getLength());
	for($i = $searchSequence->getLastIndex()(); $i >= 0; $i--)
		if($searchSequence[$i]->eq($this[i8($i)->add($ii)])->neg()())
			return no();
	return yes();
}
why am i doing this????
 
return yes();
What's that?
 
shortcut for new Truth(true) // lol
trying a full oop php
tbh with operator overloading and comparable that wouldn't look that bad
 
god. no.
 
lol. it's just fun
 
2:35 AM
God this is such a giant hack
 
still better than what i'm doing
 
hah
probably not
 
function getIndexOfFirst($searchContent){
	expecting(Instance)->check($searchContent);
	foreach($this as $index => $existingContent)
		if($existingContent->eq($searchContent)())
			return $index;
	return nil();
}
actually, better
 
2:58 AM
@Worf return no(),nil() and yes() looks really cool :D
morning
 
no it isnt xD
 
(function () {
    "use strict";
    void(0);
    var __result = factorial({ type: 4, lval: 10 });
    var cv_0 = __result;
    // opcode ZEND_ECHO wuz here
    // opcode ZEND_RETURN wuz here
    function factorial () {
        var jump = 0;
        goto_emulation:
        while (true) {
            switch (jump) {
                // opcode ZEND_RECV wuz here
                // opcode ZEND_IS_SMALLER wuz here
                case 2:
                // opcode ZEND_JMPZ wuz here
                // opcode ZEND_INIT_FCALL_BY_NAME wuz here
Such beautiful output...
And by "beautiful" I mean awful
 
lol
i even have mutable integers. just in case
 
 L6    #3     INIT_FCALL_BY_NAME      <unused>             "factorial"          <unused>
 L6    #4     SUB                     $n                   1                    @1
 L6    #5     SEND_VAL_EX             @1                   <unused>             <unused>
Ah shit.
 
Quick Question: Is it possible to iterate over a classes methods and create a closure from each method? Or should i instead make my class implement Array access so i can call its methods like call_user_func(self::$locale_filters[$key])
 
3:14 AM
function getIterator(){
    $collect = [];
    foreach($_themethodnames_ as $methodName){
        $collect[$methodName] = function()use($methodName){ return $this->{$methodName}(); };
    return new ArrayIterator($collect);
}
something like this maybe?
 
@r3wt You could iterate over it, but being able to do self::$locale_filters[$key]() sounds awesome
 
if i'm going to have to keep the instance of the class around i might as well just implement ArrayAccess. QuickQuestion, can traits implement ArrayAccess?
 
@r3wt traits can do anything
they're compiler-assisted copy and paste
But you have to add the implements ArrayAccess to the class itself
 
fuck
really?
 
Traits can't add your implements clause for you
 
3:17 AM
son of a bitch
 
But they can contain the methods
So...
 
sometimes i wonder if this language is a joke
 
class Foo implements ArrayAccess {
    ...
    use ThingImplementingTheMethodsArrayAccessNeeds;
}
 
a sick twisted joke
 
?
What's the problem?
 
3:19 AM
Our traits are a joke in my opinion.
 
I don't think they are
I think they're useful for what they are
They're not mixins
It'd be better if we'd called them snippets or something
snippet FooBar {}
 
Why can't a trait actually implement an interface?
 
@LeviMorrison That encourages misuse, I guess?
 
And why can traits define constructors on the classes they are used in? That's just nonsense.
 
But it's a good question.
@LeviMorrison It's not!
You may have a copypaste constructor.
 
3:21 AM
trait A {
    function filter() {}
}
 
Having a trait that makes a boilerplate initialisation constructor for you would be lovely...
 
Use that in a Filter class and you may have just gotten a constructor.
 
That's more a problem with PHP 4 constructors than anything else ^^
 
Traits are garbage in PHP.
 
i built a filter/modeling plugin for redbean that overloads __call() to call various functions, and even faciliate calling named closures create with Class::custom_filter(). now i want to add a 3rd order function set called self::$locale_filters, which obviously contains country specific filtering functions. Now it needs to be simple for some user to just copy my template and build their country specific function set.
i'm here collecting ideas on how i might best accomplish it
 
3:22 AM
They aren't necessarily harmful, just trashy and mostly useless.
 
but we all agree pizza is good, right?
@r3wt some code? not understanding much
 
@Andrea According to wikipedia we have mixins, since we allow state (not just method implementation)
 
@LeviMorrison Heh
 
i just realized its not even necessary to do it that way
 
I wish we had $_, or some other pseudo-variable to dispose of stuff to
So I could do foreach ($set as $item => $_) { ... }
 
3:28 AM
As proposed by the RFC our traits did not allow for state: wiki.php.net/rfc/horizontalreuse
 
One question… How is it possible to get a reference to a Generator from inside itself?
 
@LeviMorrison ...wow
 
 
@r3wt Of course that's an error. It's an infinite loop
 
3:32 AM
I need to get the reference to the Generator itself … Use case is actually returning a callable which returns a Generator…
 
instantiating Single1 requires instantiating Single2 which requires instantiating Single1
so you get a stack a million calls long:
 
I probably have to wrap the callable …?
 
@bwoebi What?
 
Single1::__construct()
Single2::__construct()
Single1::__construct()
Single2::__construct()
Single1::__construct()
Single2::__construct()
Single1::__construct()
Single2::__construct()
Single1::__construct()
Single2::__construct()
Single1::__construct()
Single2::__construct()
Single1::__construct()
Single2::__construct()
Single1::__construct()
Single2::__construct()
Single1::__construct()
Single2::__construct()
Single1::__construct()
Single2::__construct()
 
Based on what you said, @bwoebi, I do this already: github.com/morrisonlevi/Algorithm/blob/master/src/filter.php
Why do you need a reference to the generator?
Unless you mean a generator which yields callables that reference the generator?
 
3:34 AM
@LeviMorrison Lol, 'currying'
 
@LeviMorrison precisely this.
 
…would $this reference the generator?
 
@LeviMorrison no.
$this references the outside context
 
It'd work in JavaScript.
@bwoebi The general way to do this is to use by reference.
 
you need something like return function ($arg) { $gen = (function($arg) use (&$gen) { yield; })(); };
Need to wrap that an extra time
 
3:39 AM
@Andrea couldn't the interpreter catch this?
 
That annoys me
 
Why are you trying to do this, anyway?
 
@LeviMorrison Concretely thinking about how to advance Aerys response filter
(hint: there's a wip branch in Aerys now)
 
wait there's no lastIndexOf for arrays in php?
 
@r3wt Theoretically, but PHP's interpreter isn't very sophisticated
 
3:41 AM
@Worf end($array); $lastIndex = key($array); ?
 
Certain types of infinite loops can be detected, but PHP does only very trivial analysis on source code and doesn't really check for any kind of error
 
@bwoebi nope. array_search but from end
 
@Andrea Seems like a better job for static analysis than trying to do it at runtime.
 
as in js's [0,0,0].lastIndexOf(0) // 2 ... or java
 
@Trowski Yeah.
@Worf hmm
 
3:43 AM
Andrea, shouldn't PHP 7 be abandoned in favor of just forking HHVM?
2
 
@r3wt ...uh, why?
 
@r3wt guys, get your pitchforks
 
Competition is good, for starters.
 
oh, shit are you that Andrea?
 
HHVM can't run all PHP code.
 
3:44 AM
@Worf for (end($array); current($array); prev($array)) if (current($array) == $val) $key = key($array); … pretty easy … and other wise, there's still array_reverse()
 
@r3wt The one who quit? Uh, yeah.
 
Andrea Faulds?
 
Yes.
 
holy shit, didn't realize we had royalty in the room
 
hahahaha
 
3:45 AM
hah
 
HHVM doesn't handle sending or throwing into generators, which makes it a non-starter for me.
 
There is a lot of "royalty" here
King @LeviMorrison
Wunderkind Prince @NikiC
Princess @Sara
 
I'm actually a dictator, remember?
 
sorry, Eternal President @LeviMorrison
 
@r3wt pretty much everyone here is involved with php development
 
3:45 AM
(Andrea pinging random people :-D)
 
Prime Minister @ircmaxell
 
@Worf Well, many of the regulars anyway.
 
Yeah
 
@bwoebi are you serious. "pretty easy" ?? :D
 
@Worf or was involved :p
 
3:46 AM
@Worf eih… yeah?
 
@Worf you could reverse the array, search, and subtract the index
/s
 
reverse requires memory, and it's ugly anyway
 
[ @r3wt is now so impressed that he doesn't know what to say… ]
 
Heck, speaking of royalty, @PhilSturgeon is (rarely) here
 
@bwoebi i had a question i wanted to ask but i am trying to avoid taking the appearance of a help vampire
static property is a reference to a class object, need to call $function on that class. not sure if i should wrap self::$var with parens
 
3:50 AM
you shouldn't be using statics, you know that?
 
@r3wt isn't self::$var->func(); working?
(or is that thing something which changed only by uniform variable syntax RFC?)
 
if it doesn't work, Just Add Parentheses
/s
 
exactly
 
that's solid advice in Haskell though :p
In Lisp too, probably ;)
 
))))))))))))))))) // lisp
 
3:52 AM
fuck no emojis
 
@Andrea yeah, in LISP, you measure readability by the number of parentheses…
4
 
@bwoebi parentheses I think
not sure
ah]
 
yes parenthesis is singular, *es is plural
 
parenthesis is ()
parentheses is ((()))
parenthesis is singular, a pair. parentheses is plural, pairs.
 
ys, that's what i meant :P
damn programmers always so pedantic :D
 
3:54 AM
@Andrea Ah good to know… thought it'd have an invariable plural
@Worf we learn from the compilers…
@Worf Make our compilers recognize our intentions and not just the code… Then we'll be less pedantic too ;-D
 
:P
 
I seem to have a memory leak in PHP 7, but not in PHP 5. Is there a way I could get a snapshot of what's in memory to track down the problem?
 

« first day (1682 days earlier)      last day (3256 days later) »