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

2:08 PM
Hello guys , Now you can learn how to use Swager With Laravel Based API cloudways.com/blog/use-swagger-with-laravel-based-restful-api
 
@jbafford they make people feel clever.....
 
yeah, that's basically the worst reason to do anything
 
@Danack @jbafford do you guys often write anonymous functions for simple things like $names = array_map(function($foo) { return $foo->name; }, $foos); or do you prefer using $names = []; foreach ($foos as $foo) { $names[] = $foo->name; }?
 
The first
Oh I didn't get pinged :(
 
I don't often write them because I do most coding in PHP, and the long form of anonymous functions in PHP are illegible, which is why I was for the short closure RFC.
 
2:12 PM
well, for a long time, I didn't use array_map(), because I didn't see the point.
also because before 5.3, you didn't have anonymous functions, so it was a big pain in the ass anyway, unless your loop was pretty complicated.
 
I wouldn't say I prefer the latter; I'd prefer to have a syntax that didn't suck and so they could be written more clearly.
array_map($foo => $foo->name, $foos);
I can read that (even having not used it yet) - I can't read:
 
@jbafford it's about state, really. The foreach loop includes state you have to change at every iteration while array_map doesn't include any state
 
array_map(function($foo) { return $foo->name; }, $foos);
 
@Danack Beats the jizz operator
 
after 5.3, I really only use array_map when the function call overhead actually adds a benefit - e.g. making use of early returns, for example, in a way that's confusing or complicated with just a loop body.
 
2:14 PM
@PeeHaa The what now?
 
s/beats/beats off/
 
@Danack uh, I don't understand your "feel clever" comment then
 
@FlorianMargaine array_map absolutely still has that state. It's just managed differently.
 
@FlorianMargaine in 7+ you can also use array_column on an array of objects: 3v4l.org/Gp0Y1
 
2:15 PM
@jbafford not in your code. Thankfully the C side is not leaking to your code.
 
also, if you want to use the array keys as part of your map, array_map is out; it doesn't give them to you.
 
@PeeHaa LOL, I would've expected something like => ~, but I guess it's still on it's way ;-)
 
:P
 
@Oldskool that's a construct you can use now
 
@FlorianMargaine I probably ought to write a blog post on it to put it clearly then, but basically some experienced programmers will go out of their way to use language features even when they aren't needed, to make it so their code is 'less boring' and so they feel that they are using something clever which 'lesser programers' might not be used to using.
 
2:17 PM
Yeah, why wouldn't => be appropriate? Too close to other syntax uses?
 
$x ())=======D~~~~~~~ $x * 2
 
@Danack and we're back to the argument "let's make it simpler for good programmers or not because bad programmers can abuse it?"
 
@Danack Read my first functional programming book. The first JavaScript file I wrote after that was.. it was something else.
 
If I have to perform mental gymnastics to understand what the code is saying, I'm being less productive than if the code is clear.
 
or you're not used to it?
 
2:19 PM
@FlorianMargaine No, I'm saying we should have short closures, but that currently people abuse anonymous functions and use them to make their code be illegible.
 
well, I'll admit I'm not used to the short closure syntax. But I also think it's such a huge additional hurdle in readability for not a lot of actual gain.
it reminds me too much of the C function pointer syntax.
Talk about some obtuse code to read.
doubly so if you throw in ObjC block definitions into the mix.
 
hang on - let me find a link...
 
That's Zelda.
/zoidberg whoops away.
 
you asked for "a link"
 
2:22 PM
not sure if serious...
 
I'll try array_map let's see how it goes. or else I'll have to write a function to iterate that array
 
@Sean collides with arrays and yields
 
Just go one deeper
function addNumberGenerator($toAdd)
{
    return function ($n) use ($toAdd) {
        return $n + $toAdd;
    };
}
$addSix = addNumberGenerator(6);
$incrementedBySix = array_map($addSix, $arrayOfNumbers);
 
@Danack Nope, that's Link.
That's Zelda
 
8 mins ago, by Danack
/zoidberg whoops away.
 
2:30 PM
@FlorianMargaine Had this on my clipboard too LOL. Was debating whether or not to post.
 
Imagine what would have happened to Zelda, if this really happened in the game: orig10.deviantart.net/5cdc/f/2012/094/b/9/…
 
Just because nintendo likes to shake things up
 
As cool as it gets
 
@ircmaxell (or anyone) - there was a video posted in a time frame close-ish to the short closures RFC where a laravel guy was refactoring some code to be easier to read by using closures. Do you have a link to it? We discussed it briefly, but I can't find it.....
found it:
Jan 6 '15 at 2:33, by ircmaxell
http://adamwathan.me/2015/01/01/refactoring-loops-and-conditionals
 
2:52 PM
Hi, I'm working on a Laravel project (5.2). I've written a class that creates images. This class will be used in Controllers, Jobs and Commands. Where should this class reside in the Laravel structure?
 
@FlorianMargaine That video is a great example of someone using closures to make their code easier to maintain and be more readable, and then taking it one step too far and making it illegible again. You're a lisper aren't you.....so you might not see the problem. But in my opinion the final step of the refactoring takes the code from being good and easier to maintain, to being a developer showing off how clever they can be by cramming everything into a single line.
@CharliePrynn Does it matter?
 
@Danack the ->map()->sum()?
 
The inability to see the intermediate value.
 
you mean anything like ->map()->reduce() bothers you?
 
No.....only when done with anonymous functions.
 
2:57 PM
@Danack I'm not entirely sure. I'm still trying to familiarise myself with PHP frameworks. I have a feeling it should be a Provider/Factory, but I'm not sure if my understanding of those are the same as they are used in PHP/Laravel. My understanding comes from AngularJS.
 
sorry, I don't see what anonymous functions change there
 
if it used named functions, which have semantic meaning like ->map('getScore')->reduce('add') then you can see on the line of code what they are doing without also having to read and juggle the anonymous functions in your head at the same time.
To understand the final line of code in that refactor, you need to be holding too many items of information at once.
 
ah
there has to be a balance between anonymous functions and named functions, yes
but I don't really mind for short anon functions like ->reduce(($a, $b) ~> $a + $b);, really
 
And it's not a clear cut thing....like 'never use anonymous functions'......and that's what i meant by the short closure stuff being easier to read....and so being more acceptable.
 
in the end, yes, named functions always make it easier to read
 
3:00 PM
array_map($foo => $foo->name, $foos);
array_map(function($foo) { return $foo->name; }, $foos);
I find one of those is easier to parse, and hold in my head.
 
ah
I can only agree there
 
Even though techinically it's not doing anything different.
 
hi
who know what is CURLFile?
 
posted on January 27, 2016 by nlecointre

/* by Ronney */

 
@Danack i found a better solution. I'll do the sqlite query with group_concat()
that will join what a need in a csv column
 
3:04 PM
So, it has come to this.
 
one single line!
i learnt the hard way, that i should process the data in this order: database query > php > javascript
months ago when i was learning, i used to throw the heavy data all to the javascript digest it... lol
thanks for helping, everyone
gotta go
 
Hi @mahdiazarm php.net/CurlFile in php 5.5 you can't do post for a file with @ sign. You need to use it.
 
@FlorianMargaine and just to make it clear what I meant originally; at the end of that video, the guy who is doing the refactoring is having a positive emotional response; they are feeling good about themselves because they have just written some code that is clever, that lesser programmers wouldn't have written.
This is a trap. Programmers don't get this positive emotional response when they write code that is 'more boring' but is actually easier to maintain, and for other people to read. And so people have a slight tendency to write code that is 'cleverer' than it needs to be.......and once they start doing that, they get accustomed to writing 'clever' code, and so don't see why other people can't read it.
 
@Danack there is a difference between clever and elegant
I don't find his code clever, I find it elegant
and that's something he can be proud of
but yes, this is subjective and the limits are definitely blurry
 
ok, my point was that people chase the positive emotional response they get from writing code that is more clever/elegant than it needs to be, and as blurry as the line is - that is a factor in pushing people over it.
 
3:18 PM
Oh, yes, there is indeed a very big difference between clever and elegant.
 
well, don't you want to write clean code?
 
@HariKT tnx
 
It's very hard to see elegance if the code is too clever to understand.
 
ok - I've got a new rule - if you put words in my mouth I am intantly out of the fucking conversation.
"don't you want to write clean code?" - I did not say anything like that. So talk to you guys later.
 
@jbafford yes, that's why I'm saying this
@Danack err -- I don't see why that's "putting words in your mouth", but ok
 
Anonymous
3:21 PM
Just wondering, In CakePHP why is the /vendor/ directory automatically added to .gitignore ? If someone was pulling from your repo, surely this is something they would require?
 
@Jay that's what the composer.lock file is for
 
@Jay no, you use composer install to download everything in your vendor/ folder
 
You don't version the dependencies themselves. Just the list of dependences you've installed and their versions.
 
Anonymous
Ah I understand, that makes sense. Thank you
 
(we're all going to be totally fucked if github were to suddenly vanish one day.)
 
3:24 PM
Pretty sure more people would be screwed if SO disappeared.
80% of developers lose the ability to "code" around the world.
 
eh.
 
Sometimes I know how to do something and I just search SO for the answer to save myself from writing the function.
 
I agree that SO is very useful, but GitHub is infrastructure.
If GitHub were to disappear, I couldn't deploy any of my applications, at least not without redoing my deployment processes to actually copy vendors from local.
 
Yeah but you'd know how to do that. People who rely on SO wouldn't :P
 
Lot of other people would be in that same boat as well.
 
3:26 PM
@jbafford I would be.
If SO goes down I just google a little harder. If GH goes down its much worse
 
SO, on the otherhand, is just a very nice aggregation of people answering questions. Yeah, it'd be a tremendous loss of information and gathered wisdom if SO disappeared, but there's still blogs and such.
 
You're the 20% tbf
I'm just saying a large portion of developers suddenly can't function without their copy & paste style :P
 
I'm actually planning on going back and turning my more interesting SO answers into blog posts.
I think this one's been my favorite so far, at least in terms of the research I did and what I learned in answering it:
4
A: Why does array_udiff use a compare function instead of a predicate function?

jbaffordThe implementation for php_array_diff() (which supplies implementation for a number of userspace array functions) works by reusing a number of internal comparison functions. This is because those comparison functions already exist for other purposes, and meet the needed task at hand: determine i...

 
@jbafford Not really. It would suck horribly but Git is decentralized by design. So even if the public repos disappeared lots of people would still have local copies.
 
@Machavity yes, and github could be rebuilt from the ashes, sure.
 
3:30 PM
What would be hard is setting them back up with the same security. Who has THE version of a repo?
 
@FlorianMargaine I was saying that people can make code be too complicated to be easy to understand and you replied with "don't you want to write clean code?" NO WHERE DID I SAY THAT I DON'T WANT CLEAN CODE. If you don't understand why that's putting words in my mouth, I suggest thinking about it a bit.
 
@Machavity that wouldn't be too hard, given git's structure. Get enough people to agree that X version is cannonical.
 
MEDIC!!!
 
@Danack I meant that the "chase positive emotional response" is what we want when writing clean code, and "elegant" is part of "clean code" to me, sorry that you took it the wrong way
 
You might lose some fringe branches that people can't agree on, but trunks and active branches should be fine.
 
3:34 PM
oooooh yeaaaah
back home \o/
sup 11
 
wb Ronni
 
Thanks
 
yo @Ronni
 
yo @JoeW life treating you and the fam well?
 
excellent :)
yourself ?
 
3:37 PM
Great, moving sometime next month to double the size, job is ok (but a bit sick of the horrid legacy stuff which never seem to change,,) and the gf is good.. so yea.. thanks
Now I just have to choose.. spend time today on .. cryptopals, sqlmapper, bug bounty, c++ or something else
I need to just spin a bottle or something
 
free time is nice tho :D
 
heh yea, it's the best
well the bottle has choosen.. sqlmapper it is =)
 
@jbafford there are plenty of alternatives
 
@FlorianMargaine To Github? Yes. Just as there are alternatives to SO.
 
sorry, there are plenty of valid alternatives, such as gitlab
 
3:43 PM
gitlab uses sooo much resources
 
You're suggesting there aren't valid alternatives to SO. I disagree. There aren't any that are quite the same format, but people had been getting programming help on the internet for years before SO.
 
And gogs is more often broken than it's funny sadly
 
I'm not saying that SO or unnecessary, or easily replaceable. Just that it disappearing and GitHub disappearing would both have completely different (and bad) ramifications, and that GitHub's disappearance would be (at least in the short term) hurt far more badly until a replacement is procured.
 
I'm not disagreeing with that
 
4:03 PM
@JoeWatkins Yes. When the thread inherited the event loop object things usually went badly. I thought keeping the thread minimalistic was better anyway.
 
4:14 PM
!!version
 
v0.0.3-29-g1f1a217
 
user5722584
!!version
 
v0.0.3-29-g1f1a217
 
user5722584
!!commands
 
@NBOT It's still in development, please don't spam in here please.
 
4:28 PM
@Danack is the bot code open source?
 
@Patrick If you're interested in potentially working with myself and Leigh we're looking. Of course it's not remote though. And Southampton is a bit of a dump IMO. But all those negatives are greatly outweighed by the opportunity to look at my face 5/7 days a week.
 
@Jeeves challenge @NBOT to a swordfighting duel
 
Hi Guys, happy to join the chat
 
Welcome.
 
4:33 PM
Welcome
Good morning all!!!
 
5:04 PM
mornings
 
posted on January 27, 2016 by nlecointre

/* by Lluís Suñol */

 
@Gordon not the urban version of swordfighting right?
 
5:45 PM
!Hmm
seems google dont care about open redirects at all =)
 
Hi everyone. Nice to meet you all. I'm a novice PHP learner. Does knowing (at intermediate level) Javascript make it easier to learn PHP? The similarities in syntax facilitate the process of learning but sometimes I notice myself confusing some PHP and JS functions. How can I overcome that?
 
Every language you know makes it easier to learn any other language.
as far as keeping track of the separate standard libraries in PHP and JS ... there's no really good way for that.
 
I might be wrong but it seems to me that for some reason there are fewer PHP books aimed at introductory to intermediate level.
Reading manual is beyond all doubts useful but is more of a reference than a guide
 
6:02 PM
@TimurSharapov yeah....that's actually becoming a problem. Because PHP is an older language, there's relatively few people being introduced to it for the first time.....which means there's not many new books being written, and the old books are kind of out of date.
 
And those of us who have been at it for 15 years have forgotten what it's like to be new.
 
shop.oreilly.com/product/9780596100674.do - released eleven years ago......probably not that useful any more.
 
@Danack I've also noticed that. Most recommended books are outdated and I don't like the idea of learning something that is either already or about to become deprecated.
 
so it's really hard to get into the mindset of "They've never seen this before, what do they need to know to get going without being overwhelming"
 
@jbafford tell me about it.....I've been writing documentation for two projects (which will be released imminently)......and it so hard to not write "to do the thing, just do the thing, it's not that hard duh....
 
6:05 PM
Actually: here's a really good thing you can do to learn new stuff: Answer SO questions.
(And read the answers to any question that looks even vaguely interesting.)
 
@TimurSharapov amazon.co.uk/dp/1449392776/… Is only 3 years old - although it won't cover PHP 7 - it seems decent.
 
f.e., I just learned (or rather, probably, re-remembered) this:
1
A: IIFE (Immediately Invoked Function Expression) in PHP?

jbaffordIn PHP 7, yes, you can: (function() { echo "yes, this works in PHP 7.\n"; })(); This does not work in PHP 5.x. Instead, the closest you can come is: call_user_func(function() { echo "this works too\n"; });

Well-written SO questions are a great catalyst for learning.
 
stackoverflow.com/questions/4444475/… I'm using the script in this accepted answer, but I'm getting the error PHP Notice: Uninitialized string offset: 0 in /var/www/html/lnf/test.php on line 24... I can't really figure out why he's using offset 0 at all...
I'm inputting a relative URL (ex. test.jpg), and it's supposed to transform it into an absolute path... (ex. http://example.com/test.jpg)
 
@Danack thank you very much.
 
Anyone with moderator privileges care to take a look at stackoverflow.com/users/2525021/preciousmetalslive and their spam postings
 
6:20 PM
11
Q: Transfrom relative path into absolute URL using PHP

PaulHow to, using php, transform relative path to absolute URL?

 
just flag it.
 
Does anyone know why he's using $rel[0] and what that means?
 
@jbafford Although correct what OP is trying to solve is dumping stuff in the global scope. Considering php has saner scoping than JS...
 
well, yes, but neither option I provided puts anything into the global scope
 
No, but imo way have better ways to prevent it ;-)
 
6:23 PM
They didn't say it, but I was assuming they were attempting to avoid $foo = function(){}; $foo();, which would be a pollution of some namespace.
 
> yes, every time writing PHP code, I have to make sure no duplication in naming convention by using prefixes $t_my_var for temporary, $g_my_var for global, scoping with private and enclosing with class MySuperClosure{ } to avoid duplication
So yes your answer "works" but OP is going to take it and use it like ^:-D
 
Anyone... I'm sure its a trivial bug...:
http://stackoverflow.com/questions/4444475/transfrom-relative-path-into-absolute-url-using-php I'm using the script in this accepted answer, but I'm getting the error PHP Notice: Uninitialized string offset: 0 in /var/www/html/lnf/test.php on line 24... I can't really figure out why he's using offset 0 at all...
 
hi guys is doing this htmlspecialchars($string) okay or do i need to htmlspecialchars(strip_tags($string)) ?
 
okay for what?
 
6:31 PM
!!version
 
\o/
 
@kelunik ooh, with link :-P
 
Oh nice. Missed that one when pulling
 
Yup, didn't realize that g isn't part of the commit hash at first. It's not even hexadecimal. ^^
 
6:32 PM
@ChrysUgwu Both are perfectly fine, if each is what you need to do.
 
kk
how can i fix this am trying to submit a form conatinig this 'echo htmlspecialchars('<?php if($m && $n) ?>');' but when i try outputting it to a page i have this 'echo htmlspecialchars('&lt;?php if($m &amp;&amp; $n) ?&gt;');' is there a way to sanitize this and retain its orignal format?
 
you aren't sanitizing it - you're formatting it......and the final result is what you want, it's just that you've missed something else.
specifically &amp; is what you want to display an '&' on a page.
 
6:49 PM
When you have a string $string, what does $string[0] mean?
 
ThW
@HelpingHand character index
 
Interview question of the day: "what do you have against frameworks?"
Maybe I should have picked a different name for my tutorial...
 
"what do you have against frameworks?" - they don't lead to maintainable projects.
boom headshot
UX fail - where the heck is the page for creating tags?
 
@ThW Oh, okay... Thank you.
 
@Danack i read it whole still.. didnt help. and u said am not sanitizing. so i cant save data into my DB after rendering them to htmlspecialchars?
 
6:58 PM
you really don't want to alter any data before saving it to the database. The only time you want to escape the data is when you're going to be displaying it in a particular format where it needs to be escaped.
 
@Danack There isn't any?
Just add them to a question
 
@ChrysUgwu Please read this answer I wrote about what type of data validation methodology to use where. You're setting yourself up for a world of pain if you try and perform escaping/encoding/validation at the wrong place.
 
hah
user image
4
oh. bah. it doesn't include the image?
 
k so this is it. i have a post form
and this is how i save $post = htmlspecialchars($_POST['post']);
SAVE TO DB($psot);
this is how i display to page echo htmlspecialchars($post);
is this really bad. am new to PHP so some terms u guys use just dont click
 
7:09 PM
@ChrysUgwu Please format your code - hit Ctrl+K before sending and have a look at the FAQ.
 
@kelunik ^
We should probably heavily limit that
 
phew yeah :p
 
7:28 PM
@Jeeves it striped it out
 
@ChrysUgwu yeah don't mind him he's an asshole and nobody likes him
 
ARGH
 
guys please i need an answer.
 
@ChrysUgwu @Charles already pointed you to a posts where it is stated you are doing it wrong
The function even has html in it. And a database is not an html page
2788
Q: How can I prevent SQL-injection in PHP?

Andrew G. JohnsonIf user input is inserted without modification into an SQL query, then the application becomes vulnerable to SQL injection, like in the following example: $unsafe_variable = $_POST['user_input']; mysql_query("INSERT INTO `table` (`column`) VALUES ('$unsafe_variable')"); That's because the us...

Wow that only took me 30 minutes to find...
> PHP Fatal error: Interface 'Aerys\WebSocket' not found in /srv/Amplify/src/Handler.php on line 11
Case sensitivity is a bitch
Yes but you use it when displaying data not when saving it to the database
Othwrwise you end up with encoded crap in your database and all hope will be lost
 
That is, unless you want encoded crap in your database, which might be a valid use case for the given input.
Regardless, you need to decide and be consistent with your input filtering.
 
7:40 PM
@PeeHaa Well, websocket is a single term, not "WebSocket" (for me)
 
@Charles When would you ever want encoded crap in your db?
@bwoebi It's borderline to me, but I tend to lean the other way
And ofc what I think is best :P
 
^^
 
@PeeHaa Well, for example, storing both the raw and markup-processed version of a chat/forum post. The post-processing version can easily contain both HTML and encoded HTML, but I'll know that it's safe to display raw.
 
eeeew :(
<?= markup($post); ?>
 
Yeah but if your markup processor is a dog...
See also: HTMLPurifier.
 
7:42 PM
@PeeHaa and what's Amplify for a project, if I may ask?
 
If I have to render 100 things per page, I'm not gonna want to invoke it 100 times. Caching, yo.
 
Fair enough, but it still feels icky to me. But yea
Also
2 mins ago, by PeeHaa
And ofc what I think is best :P
 
If a method of class Foo returns a callback that accepts a typed parameter (say, Bar) would it be accurate to say Foo depends on Bar?
 
@bwoebi MVC framework thingy
or something like that not sure yet what it is going to be for now it's a useless project
s/useless/awesome
Will run it soon
 
s/run/ruin/
 
7:44 PM
Same thing :P
 
okay now it make sence. but what if i dont want to encoded crap and dont want to strip_tags is there any other option. just want data to straight to my db since am using prepared statment?
 
@NorthbornDesign It depends on what you mean by depends. Depends as in DI, no. Depends as in requires it to be present and valid, yes.
 
@ChrysUgwu yea
@NorthbornDesign I am agree with @Charles
 
Okay, now if the Foo method instead returned a functor object, that had an explicit parametric dependency of Bar, same thing?
 
7:47 PM
@PeeHaa whats the option or its safe?
 
class Foo {
    public function getQux() { return new Qux; }
}
class Qux {
    public function __invoke(Bar $b) { }
}
class Bar { }
 
@ChrysUgwu If you use real prepared statements with bound parameters using the correct encoding you are at least safe from sql injection
 
this is what i use
$stmt = $mysqli->prepare("INSERT");
$stmt->bind_param("");
$stmt->execute();
$stmt->close();
 
@NorthbornDesign Well, it depends on where it gets the Bar from, but I'd edge more towards yes than no on the dependency question.
 
@PeeHaa I like things much more when they aren't called MVC :-D
You can build an MVC-like architecture without focussing on MVC ...
 
7:58 PM
@bwoebi Well it's actually MVC so :)
Not that crap that is currently in the project btw. That is just me dicking around
 

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