« first day (1719 days earlier)      last day (3226 days later) » 

5:00 PM
@Ja͢ck agreed.
I'd also like an array_find, i.e. array_search with a user-defined callback
basically... all the array functions that made it in es5/6
 
@FlorianMargaine You mean array_filter?
 
Anonymous
anyone knows a good book on security and php?
 
@Sherif no, filter returns an array, not a single element
(array_search returns a single element too)
 
@FlorianMargaine So array_filter is even better then :)
 
Anyone good with math here?
 
5:06 PM
1 + 1 = 0
Sure
I nailed that
 
:worship
 
@Sherif it's different.
 
@FlorianMargaine The bigger issue here, for me anyway, is that array_filter() is always O(n), as is array_reduce() (which could be used in the same way). Either one of those would be fine if you could short-circuit them
 
@FlorianMargaine Sure it copies the value, which may or may not be desirable, but I prefer non-destructive search.
s/search/map/filter
 
@DaveRandom yes, that's because I love the short circuit feature that I want array_find and array_some/every :)
 
5:08 PM
/me would usually rather just write a foreach, but whetever
 
@Sherif ? I'm talking about search with a callback, non destructive too
 
PHP's arrays are definitely not O(n) as far as search goes.
 
@DaveRandom you can say the same for map/filter/reduce
 
Your best case scenario is going to be O(n).
You're far more likely to hit O(n*2) or even worse O(n^2)
 
@FlorianMargaine Indeed, and I don't use them very much either
 
5:09 PM
sans PHP 7
I have no idea what thing does to arrays.
 
@DaveRandom I do, and I feel the missing ones :)
 
Fair enough
 
array_map especially, is the one I use the most I think
 
You know you can actually build more efficient data structures with objects rather than relying entirely on arrays.
For example: btrees, tries, dafsas, etc...
 
in most cases, arrays are good enough
 
5:13 PM
I've actually come to hate arrays in PHP, personally, but then again much of my problems have to do with tuning performance at a very large scale. Something arrays certainly can't always do very well.
Definitely not the normative case.
For example, array_merge is actually slower than just using a simple foreach($arr as $k=>$v) { $newArr[$k] = $v; }
 
@FlorianMargaine Which is exactly why I prefer objects over arrays in PHP :)
 
@Sherif read the thing. It's satire.
 
@FlorianMargaine So what's your point?
 
@Sherif nothing, was trying to make a joke.
but you're not helping :)
 
5:21 PM
@FlorianMargaine Wait a minute, have we met before? What delusion made you think I have a sense of humor?
That's just crazy talk.
 
@Sherif You have, obviously. So.
 
@bwoebi Hey man, don't go telling people that. I have a reputation to uphold :/
 
lol
 
in php, how do i convert true to false and false to true
 
!!
Just like you would in mostly any other language
Truth in value
 
5:32 PM
so !!true == false?
 
no
But !true == false
and !false == true
 
yeah, thats what i thought
same as javascript
 
Should be the same universally sans syntax
But say your function returns something that's not always boolean... return !!$value XOR !false; // always ensures false when true and true when false
 
dang my internet is broken =[
 
function always returns bool. i strict typecast all functions return value
 
6:05 PM
posted on July 01, 2015 by kbironneau

/* by Thomas C */

 
Hm.. when do we have that yield disallowed in finally again? 3v4l.org/ATlNR seems to work. @bwoebi
 
@kelunik 3v4l.org/nemSX ;-)
uh…
wait
 
@bwoebi Nope, I tried that already, it executes the yields in the finally perfectly.
 
@kelunik 3v4l.org/3YAZZ but that one.
 
Oh, finally will even be executed if the execution didn't continue. But I don't know why that happens in Aerys.
 
6:18 PM
what happens in Aerys?
 
@bwoebi Cannot yield from finally in a force-closed generator.
I thought it was because of a return, but as it seems, it's not.
 
6:31 PM
@bwoebi unset() can throw, who knew? 3v4l.org/hXHUl
 
@Trowski yeah, side-effects ftw.
nearly everything can throw.
 
@bwoebi Yeah, I just found that case pretty unusual.
Interesting that HHVM eats the exception though ...
 
^^
 
@Trowski It doesn't eat it, it just never runs your code
 
Oh ... even better :P
 
6:36 PM
@PeeHaa Are you just wanting to send notifications to friends programmatically? If so, your app will need to be "legit" by abiding by the platform policy. Facebook is pretty hardcore about the platform policy. :) Then you might be able to tie into the notifications API.
 
Bah I suck at io
 
@SammyK Does that also allow me to send to friends of my users?
Or only people who have used my app?
And yeah facebook is pretty hardcore asshole. The last time I did smething funky not only my account was blocked, but also that of the client including all apps :P
 
@PeeHaa you should make your own facebook, with blackjack, and hookers ...
 
:D
 
Doesn't Facebook already have blackjack and hookers?
 
6:48 PM
@PeeHaa Unfortunately, yes, you are. But thank god, you can disable those notifications globally meanwhile.
 
@kelunik Yeah I am one of those assholes ;)
Reporting it as spam is very effective though
 
I don't care, I have disabled them for all apps. :)
 
:)
 
@AllenJB yeah, but not on purpose ...
 
6:52 PM
@Fabor That would make a proper codinglove post
 
"Using PHP for the first time" ^
"Everyone falls the first time..."
 
Anonymous
do we have a function to put 0 for 1-digit numbers?
 
Anonymous
as in 01 .. 02 .. 03 .. upto 10
 
?
Yes
it's called padding
 
Anonymous
pray tell
 
Anonymous
6:57 PM
hm?
 
STR_PAD()
 
@Fabor Staph shouting at your texteditor!
 
It's actually called, sprintf, but I'm old school so...
 
Yeah also valid ^
 
heh
 
Anonymous
6:58 PM
nope str_pad ain't it.
 
printf("%02d", $num);
 
@samaYo Why not?
 
str_pad can do the same thing, sprintf is just a lot more versatile and goes beyond just strings.
 
Example @samaYo
 
Anonymous
thanks .. I actually knew that function before, but I only associated it's use with string padding...
 
Anonymous
7:01 PM
@Fabor
 
Anonymous
I was also hoping to find a function that does this ... like a math function ..:/
 
Too bad no one mentioned sprintf then.
 
lol
 
Anybody knows of any "must have" xbmc addons?
 
Anonymous
... and off we go
 
7:23 PM
	$doc->loadHTMLFile("https://foo.com/books/{$page}/1.htm");
	$doc->saveHTML();
Why!?
 
Anonymous
Mistake!
 
@Danack hehehe
 
Anonymous
After many failures, and errors this seems to do the trick.
 
Anonymous
$doc = new domDocument();
libxml_use_internal_errors(false);
$doc->strictErrorChecking = false;
$doc->recover=true;
foreach (range(1, 66) as  $page) {
	$page = str_pad($page, 2, "0", STR_PAD_LEFT);
	$html = "https://foo.com/books/{$page}/1.htm";

	$file = file_get_contents($html);
	$file = html_entity_decode($html);
	$doc->loadHTMLFile($file);
	$html = str_replace(["https://foo.com/books/{$page}/", "/"], ['', '-'], $html);
	$doc->saveHTMLFile($html);
}
 
Anonymous
7:26 PM
ehm .. this is also my first time tinkering with the Satan's DOM
 
Anonymous
I still have one problem though, for each /book/page there are chapters i.e (1.htm) ... and I need to download those chapters .. otherwise .. the script only saves the first chapter :/
 
Why are you using html_entity_decode?
That kinda looks like something you actually don't want to do
 
Anonymous
kept getting errors due do to some encoded entities ..
 
@samaYo But if you ignore those do you get the document proper either way?
 
Anonymous
Haven't tried .. since it already works as is.
 
7:31 PM
I'm always using @$doc->loadHTMLFile($file); for DOMDocument, because there's always something wrong.
 
Anonymous
of what?
 
The thing you are trying to "borrow"
 
Anonymous
 
Good evening all!
 
7:34 PM
Wait wat. Why are you using DOMDoc in the first place? You only want to change the external links to relative links right?
 
Anonymous
yeah .. oO
 
user image
2
 
Anonymous
curl ? that thing doesn't work for me.
 
Can't you just use file_get_contents -> file_put_contents if only you are going to do a str_replace?
 
Anonymous
Oh, nope .. I just realized what I was going for .. :/
 
7:37 PM
@samaYo Use Artax instead. ;-) file_get_contents has weird edge cases anyway, like not automatically closing keep-alive connections, but that's probably a bug I should report.
 
Anonymous
If that was the case, it would've been easier ..
 
Well FWIW you can do:
 
Anonymous
@kelunik haven't tried that yet .. I needed this job to be quick, so I'll go with caveman job on this one.
 
<?php

$doc = new \DOMDocument();

$errorState = libxml_use_internal_errors(true);

// do your DOM stuff

libxml_use_internal_errors($errorState);
This should hide the errors you will otherwise get
 
Anonymous
ah thanks .. I'll do that.
 
7:39 PM
While you have it in the dom it should be trivial to get next pages btw
Too bad we still don't have a querySelector* but a simple xpath query should work just finr
 
Just a small help regex101.com/r/vY4kZ9/1 :D :name should be matched, until whitespace.
 
Also it's not like the bible is going to change often so it's not something that has to be future proof :P
@VeeeneX (:\S+)?
 
@VeeeneX (:[^\s]*) ;-)
 
Anonymous
Once I save all the pages now, I can go home and extract the juice using xpath from each page and send the content to db ... /no internet at home/
 
@PeeHaa Yes, that would be pretty nice. But there's code.google.com/p/phpquery ^^
 
7:46 PM
E_TOO_MUCH_JQUERY
 
Anonymous
Oh, btw @Sherif welcome to your new home. It's too tiny for your ego but you'll fit in.
 
@PeeHaa @kelunik Thanks both are nice but I thing how to match all of them ?
 
BTW @samaYo you could also drop that file_get_contents from there assuming allow_url_fopen is not disabled
@VeeeneX That will match all of them
 
user4268046
Greetings, I just switched from Java to PHP.
 
@TheMineBench What did you do wrong in your life to deserve such a punishment?
 
user4268046
7:50 PM
I am trying to access on class that is in a different file, and it's giving me a 'Class not found'
 
user4268046
I am working with Minecraft PE.
 
user4268046
Just game from Minecraft x)
 
@TheMineBench How "fresh" are you in php?
 
user4268046
Come again? Have fresh?
 
@PeeHaa Oh, thanks just regex101 hasn't shown all of them
 
user4268046
7:51 PM
Ah, started yesterday morning.
 
@TheMineBench Yeah typo. It's hot over here and my brain stopped functioning somewhere this afternoon
 
user4268046
At least it was functioning at some point...
 
@TheMineBench ok :) The easiest thing you can do require_once __DIR__ . '/path/to/your/class/relative/to/the/path/this/file/is/in/Class.php';
@TheMineBench :P
 
user4268046
is that equivalent to importing?
 
user4268046
And how is it different from use class/myclass.php?
 
7:53 PM
Well...
Lets just say kinda :)
 
@VeeeneX Just add a g to the modifiers on regex101.com
 
@TheMineBench Because use doesn't do what you expect it to do from a sane language
Or even java for that matter ;)
 
I have to develop a small submit script for internal use, simple textarea and submit button, but there is effect need for submit like on trello, if i submit then is automatic updated, which technology should i use for this effects? I know it's "ajax" but i'm not so familiar with javascript, is there any library or to develop from scratch?
 
use "imports" the namespace but you have to take import with a grain of salt here
 
@m_73 jQuery
 
user4268046
7:55 PM
@PeeHaa When I run my plugin on the server, it works without needing to require_once. but when I try to just execute the php file it throws the error.
 
Probably that thing has some autoloader would be my guess
 
The word "imports" is very misleading. use actually just aliases the namespace. It doesn't import anything.
 
@VeeeneX ok. but i seen in other works jquery has sometimes problems with compatibility, how can i avoid it? Because my script i have to implement in few other systems...
 
user4268046
Is there a way to use the autoloader when executing a php?
 
@Sherif The word use is very misleading to begin with...
Asshole php
 
7:56 PM
@m_73 What you mean by other systems?
@TheMineBench Yes
 
@PeeHaa Might have something to do with the fact that namespaces were an ad hoc implementation that only made it in at the last minute
 
@VeeeneX this is for internal use, but i have to implement it in a few other sites, some are custom but there are also some wordpress and joomla sites
 
@m_73 jQuery is build on top of the javascript
It should works
 
@Andrea I'm debating writing a new language centered around the concept of tuples. Have tuple math be first-class. So (1) + (2) is (1, 2), etc... So a function call can be a(1, 2) or it can be args=(1, 2); a args;
hence letting you do math on the arguments and meta-program
 
Sounds Lispy
 
user4268046
7:59 PM
@PeeHaa They are in the same file...
 
@VeeeneX node.js is not required? Sorry for bad questions but i'm still not sure...
 
@TheMineBench Can you post your code in a gist?
 
user4268046
http://hastebin.com/cujayegeko.coffee <- the file I execute
http://hastebin.com/yujefizaje.tex <- the other file
 
You have to add the leading / when using require_* wìth __DIR__
 
You mean \
It's not an include problem. It's a namespace problem.
Read the error message carefully.
 
8:03 PM
All I am saying is that this can never be correct
require_once __DIR__ . 'mineplex\plugin\bench\game\components\gamestate\GameState';
 
@m_73 Nope node.js is server side as php.
 
oh sure, that
 
You can tun it without node.js
 
@Sherif it is, to some extent
 
Also you are missing the extension
 
8:04 PM
@ircmaxell Love me some Lisp :)
(+ 1 2)
win
 
That code you have should blow up
 
@Sherif this would be different though, because it would be + (1, 2)
 
awww no prefix notation allowed :(
 
@m_73 But it depends if you want to check if user is connected or if textarea has been updated, then it's good to use sockets they are avaible in php and in node.js too
 
user4268046
I changed it to: require_once DIR . '\GameState.php'; and that seemed to work...
 
8:07 PM
@Sherif well no, because 1 + 2 could be 1(+)(2)
 
@VeeeneX i want simple if i add content in this textarea then:
1. Add content in the list
2. Automatic update list
3. Send email to users

The system is only for registred users, so don't need to check if the user is there...
 
@ircmaxell Hmm, what's the difference? You're just allowed to wrap any expression in a tuple?
 
@m_73 About point 2. Automatic update list on client side?
 
@Sherif no, that executes the 1 funtion with a argument of +, which returns another function which is called with 2
 
@VeeeneX yes, if i add then update automaticly for all users who are on this page
 
user4268046
8:10 PM
@VeeeneX How does one do that?
 
@ircmaxell So a constant can be a function?
 
@m_73 You have two options sockets or ajax, i will explain easy ajax way imagine script that executes it self every 5 secs, it makes post on server ask if new data has arrived and if it so send it to user, easy.
 
@Sherif what says it's a constant?
 
@VeeeneX what's recommended to use? I have only experience in ajax with contact form sending, and about sockets no idea...
@VeeeneX i'm also interssted to learn the recommended solution because i will need it also in future
 
Yes, that's true but I'm not expert on sockets so...
 
8:18 PM
@ircmaxell So basically constants become constant functions, is what you're saying?
 
I don't know what I'm saying
 
lol
Then we're on the same page :)
 
sounds good to me
 
@VeeeneX sockets are php related?
 
8:23 PM
Constant is a pure function that has no input
 
> A constant function is a function whose (output) value is the same for every input value.
 
but what does it return?
it can only return another function
so does 2() return two functions?
 
Functions that return a function are typically called higher order functions. Constant functions just have a constant value regardless of their input. So y(x) = 1 will always have a value of 1 regardless of the value of x.
So if you're telling me that 1 can be a function, I would assume that you're going for 1 = y(x) where it's operands are then its input values.
Though the function itself will always have a value of 1.
But I have no idea what were you trying to say so...
 
@Sherif my point is that there is no such thing as a primitive, because everything is a function
so if everything is a function, how do you symbolize anything?
 
Aww man you're getting into Haskell territory now. That's gonna make my brain hurt.
 
8:31 PM
precisely
alright, I'm almost at my train station, later
 
@PeeHaa How would you handle the active state in amp-chat? Currently, it changes to away whenever you move the tab to the background (switch to another tab) if there's not at least one active client for a user. But that requires saving the state of a WebSocket connection and that's not available in the REST API, because there's nothing like a persistent WebSocket connection bound to each client.
 
Trying to add support for opcache… Turns out opcache has a bug -.-
 
8:48 PM
@bwoebi What's the bug?
 
@Sherif memory leak in opcache
With my temporaries patch I get an assertion failure^^
 
@bwoebi heh, memory leaks aren't bugs, silly. They're a feature that forces you to turn off swap.
 
@Sherif just that this particular bug which causes the mem leak also causes my code to fail
 
Write better code
 
HAHA
 
8:53 PM
Clearly when the hammer doesn't work it's the person using it that's broken.
 
when did var_dump become so ugly
 
When was it ever pretty?
 
it used to be kinda ok :P
argh. no taskbar button for phpdbg on windows
 
9:13 PM
@RonaldUlyssesSwanson You've probably been spoiled by the xdebug version of it.
 
nope, never used xdebug, except for phpunit
someone willing to help a noob with phpdbg? i'm on windows and i just downloaded the jar gui. there is no way i can debug php as apache module is it?
 
You could use -S
But you're developing on Windows, so who cares...
 
@RonaldUlyssesSwanson try using PHP 7 first^^
and then compile with --enable-phpdbg --enable-phpdbg-webhelper
 
10:19 PM
@Trowski Did you mean:
$obj = (ClassNameOrScalar) $object; // Invokes $object::__cast('ClassNameOrScalar');
 
Why is this notion of banning encryption even still floating around
 
@Fabor He's being advised by people who are insane.
 
Experts who also know nothing about technology then
 
Mostly, though a lot of people in GCHQ know about tech.....and know that the like being able to use it to nefarious ends, rather than aims that actually help the country.
 
Good luck trying to enforce that.
 
10:43 PM
 
I don't like it.
Let's all move to the Netherlands.
 
10:58 PM
blog.mattbierner.com/… … I have no apt words to describe this abomination…
 
Should have sent a poet?
 
@Danack Do you think a poet could aptly describe that?!?
 
Inferno (Italian for "Hell") is the first part of Dante Alighieri's 14th-century epic poem Divine Comedy. It is followed by Purgatorio and Paradiso. It is an allegory telling of the journey of Dante through Hell, guided by the Roman poet Virgil. In the poem, Hell is depicted as nine circles of suffering located within the Earth. Allegorically, the Divine Comedy represents the journey of the soul toward God, with the Inferno describing the recognition and rejection of sin. == Overview and vestibule of HellEdit == The poem starts on Maundy Thursday in the year 1300. The narrator, Dante himself, is...
 
@Danack even the sum of all nine circles won't be enough.
 
YAY!
function foo($a, $b) {
    $c = "foo";
    $a = mysql_real_escape_string($a);
    $b = mysql_real_escape_string($b);
    mysql_query("SELECT * FROM foo WHERE id = '$a' AND name = '$b' AND foo = '$c';");
}
function foo2($a, $b) {
    $c = "foo";
    $a = mysql_real_escape_string($a);
    mysql_query("SELECT * FROM foo WHERE id = '$a' AND name = '$b' AND foo = '$c';");
}
 
11:06 PM
^ someone's happy :-)
 
my script properly identifies foo2 as vulnerable to SQLi, and foo as safe
 
nice
 
well, more specifically, it identifies the $b parameter as being un-escaped, which then propagates bac
 
I remember writing an extension that does that.
Man, that brings back horrific memories
 
this does it purely though static analysis
 
11:17 PM
But what happens if they use variable variables?
Static analysis be hard when code is horrific :/
 
I error
 
Or just throw a pie at them from over the ethernets
 
@ircmaxell you'll have fun… Apply mysql_real_escape_string via foreach() on each of $_REQUEST. Static analysis probably will fail here
 
so, I'm planning on 2 levels of error:

1. Critical: I can show you a specific request variable that is vulnerable
2. Warning: I can show you an internal variable that's vulnerable. May not be exploitable
@bwoebi nope, I'll catch that
 
@ircmaxell when that happens at startup?
interesting
 
11:19 PM
yup
though it depends on how that code gets loaded whether I can prove that it's actually safe or not
 
direct (relative) includes.
with a loop like

foreach ([$_GET, $_POST, $_REQUEST] as &$array) {
    foreach ($array as $&val) {
        $val = mysql_real_escape_string($val);
    }
}
If your static analysis understands that, I'm really impressed.
 
I wouldn't rule it out, not sure though
actually, it should understand it
because it knows about references and static iteration alrady
<?php


function bar() {
    foo(1, $_POST['a']);
}

function foo($a, $b) {
    $c = "foo";
    $a = mysql_real_escape_string($a);
    mysql_query("SELECT * FROM foo WHERE id = '$a' AND name = '$b' AND foo = '$c';");
}
> PHP Fatal error: Uncaught exception 'LogicException' with message 'Possible injection found in test.php:5 call foo, argument 1'
:-D
holy crap it works
holy crap it works.
holy crap it really works
/cc @BenjaminGruenbaum @NikiC
 
11:39 PM
\o/ :-)
 
@NikiC I just pushed an incredibly broken SSA implementation, and the foundations for the SQLi engine
3
 
I seriously need to have a closer look at your code…
 
run demo.php in master
 
@ircmaxell Curious to know what happens if you did mysql_real_escape_string($_POST['a']) at some point prior to calling bar()
 
15 mins ago, by ircmaxell
actually, it should understand it
 
11:44 PM
right now, it won't, because I haven't taught it array operations yet
 
oh… it understands iteration, but not array, okay
 
there's nothing stopping that though, I do SSA the global scope
which means I have a DAG if I want it
@bwoebi it's not implemented today, but conceptually there's nothing stopping it
I built this in the past 1.5 hours sitting at a bar drinking. Don't blame me for partial implementations
 
totally not blaming you. I just thought when you understand by-ref foreach, you'd understand arrays too^^
 
Arrays are tricky though because they carry their references with them.
 
well...
 
11:47 PM
So it's not trivial to statically analyze their values.
 
@Sherif that's a completely other beast…
 
yeah, My goal is to have it say "I can't prove it's safe, so please don't use such dynamic code"
 

« first day (1719 days earlier)      last day (3226 days later) »