« first day (2286 days earlier)      last day (2887 days later) » 

22:00
@Tiffany I mean, why not two objects? One that is completely generic/agnostic, and calls an interface, which you wrap in the coupled class?
If it's going to bother you that much
@Dereleased I don't have the time to. I'm going to be spending enough time trying to figure out how to write this class as it is.
not just trying to figure out if I'm doing something right, but just figuring out how to do it
so that it works
@Tiffany In that case, don't worry about it. Having code you hate is just par for the course. I'm sure that by this point in the afternoon I'd hate the code I wrote this morning if I hadn't been doing reviews and design all day.
a great deal of programming involves apologizing to future me and grumbling about past me
6
@Tiffany Then you will truly have made it
@Dereleased This is how I feel about some of my really old CSS and HTML.
I'm reading a third-party vendor's code, send_mail, which receives three parameters, $to, $content, $headers. If the email has an attachment or must be send as HTML, they are keys in the $headers array. I can't help be think there's a better way of doing this. Like having an $options array.
if (array_key_exists('html', $headers))
  {
    unset($headers['html']);
    $mime->setHTMLBody($content);
    $mime->setTxtBody(strip_tags($content));
  } else {
    $mime->setTxtBody($content);
  }
otherwise this happens
well I guess that's one way to approach the "problem". My guess is they had an interface that couldn't change. Hence this hack.
@Dereleased I'll send you the code snippet. There's no reason not to have an $options parameter.
gist: 769e1c53dcd75677a4259e1e5b4680c7, 2017-01-18 22:36:58Z
function send_mail($to, $content, $headers)
{
  require_once('Mail.php');
  require_once('Mail/mime.php');
  $mime = new Mail_mime();


  //debug($content);

  if (array_key_exists('html', $headers))
  {
    unset($headers['html']);
    $mime->setHTMLBody($content);
    $mime->setTxtBody(strip_tags($content));
  } else {
    $mime->setTxtBody($content);
  }

  if (array_key_exists('attachments', $headers))
  {
    $attachments = $headers['attachments'];
    unset($headers['attachments']);
    $attachments = (is_array($attachments)) ? $attachments : array();
    foreach($attachments as $attachment)
    {
      $mime->addAttachment($attachment['file'], $attachment['type'], $attachment['name']);
    }
  }

  $body = $mime->get();
  $headers = $mime->headers($headers);

  $mail =& Mail::factory('mail');
  $mail->send($to, $headers, $body);
  if (PEAR::isError($mail))
  {
    file_put_contents(SITE_URL."error".DS."pear_mail.log", $mail->getMessage(), FILE_APPEND);
    return false;
  }
  return true;
}
wait
I don't think that's the production code
let me post prod code, without my alterations that didn't work.
Wes
Wes
@marcio if you wanted to change your vote, the rfc has a slight "yes" advantage right now.... with 4 more votes it would pass :B
22:39
gist: 53ed78b17f0a5519984f509ab6ff6c8a, 2017-01-18 22:39:41Z
function send_mail($to, $content, $headers)
{
  require_once('Mail.php');
  require_once('Mail/mime.php');
  $mime = new Mail_mime();


  //debug($content);

  if (array_key_exists('html', $headers))
  {
    unset($headers['html']);
    $mime->setHTMLBody($content);
    $mime->setTxtBody(strip_tags($content));
  } else {
    $mime->setTxtBody($content);
  }

  if (array_key_exists('attachments', $headers))
  {
    $attachments = $headers['attachments'];
    unset($headers['attachments']);
    $attachments = (is_array($attachments)) ? $attachments : array();
    foreach($attachments as $attachment)
    {
      $mime->addAttachment($attachment['file'], $attachment['type'], $attachment['name']);
    }
  }

  $body = $mime->get();
  $headers = $mime->headers($headers);

  $mail =& Mail::factory('mail');
  $mail->send($to, $headers, $body);
}
Wes
Wes
dem walls
@Wes do you watch what'shisface?
Million Dollar something
Wes
Wes
the what?
ah, nevermind
Wes
Wes
i meant, if you add another character to the gist link, it won't visually monopolize the chat, as it would appear as a link rather than a whole listing :B
22:42
There's this youtuber that my friends watch, and he posts some of the most ridiculous videos. There was one where he poses as a pick-up artist and says he has all of the answers, waits until the end of the video to tell them, and says the answer is to be overweight or something, "gotta have dem guts, dem walls" or something
Wes
Wes
lol, nope i don't know that... link? :B
I'm trying to remember his name
when TedX let the public speak at it, he has a presentation, and talked about essentially nothing for like 10-15 minutes
oh god I found it
I like it when the thumbnail lets you know to not bother watching.
@PaulCrovella It really is a waste of time unless you like watching cringey shit
@Tiffany so was there a question or were we just mocking the design?
22:48
@Dereleased mocking how the $headers array is used.
ok cool
/me goes and looks for fun point-and-laugh images, brb
mm yeah, those are nice
Wes
Wes
@Tiffany can't wait for the end of this now AHAHHA
lol
@Wes I apologize in advance
Wes
Wes
well that was a bit disappointing :B
@Wes here's where he talks at Ted X for the public: youtube.com/watch?v=-yFhR1fKWG0
where he wastes about 15 minutes of everyone's time
22:53
@Tiffany have you seen the "Unforgivable" videos?
@Dereleased Nope :o
@JoeWatkins 2-3 patches and you think I'm comfortable with openssl? :D
maybe I should really deep-dive libsodium, for some AoT knowledge eh
is it possible to store a boolean value into an array?
$array[] = $booleanValue
Tiffany, did you sleep recently?
^^
23:03
I mean can I do if ($options['html']){} or should I do it if($options['html'] == true){}
@Leigh I'm just not very bright.
@Tiffany it is almost never necessary to type == true in a conditional
@Dereleased right, but it depends if a boolean can be stored in an array.
or if (isset($options['html']) && $options['html'] === true) {}
@Tiffany anything can be in an array
the entire symbol table is in an array ($GLOBALS) that might be poorly worded actually
My advice is to be explicit
23:06
I'm using old code as an example, which is using array_key_exists(), though I think isset() might be better
!!docs isset
[ isset() ] Determine if a variable is set and is not NULL
Write meaningful code, don't worry about performance (as they cheer "hypocrite" at me), write code that is verbose and makes it obvious what the intention is
@Leigh @Tiffany code must be written for programmers to read, and only incidentally for machines to execute
Wes
Wes
isset is false when the array key doesn't exist or it is null
array key exists is false only when the array key doesn't exist
And good compilers will optimise out your verbosity
Let them do their job
23:07
@Dereleased why does Perl exist?
@Tiffany Why are you asking me?
The ultimate comeback does not work on us... /me waves hand ... droid bleeps
@Dereleased I'm just asking hypothetically, in response to your statement :P
@Leigh Oh cool did PHP get one of those? =P
When compiling PHP if I set --with-system-ciphers does that override --with-openssl=/some/dir/path?
23:09
Blame Nikita for a lot of it, the compiler has gotten a lot of really awesome improvements over the last couple of years
@crypticツ uhhh, I never knew there was a "--with-system-ciphers" flag, is that an openssl specific flag?
@Leigh =)
@Dereleased Just so we're clear, compiler doesn't necessarily mean "compiles to machine code"
@Tiffany Perl is known to be a write-only language, don't worry about it =P
@Leigh Yes, I am aware
@Dereleased also, something something brainfuck
@Leigh php-src has it here: github.com/php/php-src/blob/PHP-7.1/ext/openssl/config0.m4#L12 don't know what hardcoded values it's referring to.
23:12
@Dereleased Just making sure, you're a relatively new name here, haven't got the hang of you yet
@Tiffany so you can do this
@PaulCrovella such a work of art.
@crypticツ so it works with --with-openssl
it's a configuration override
I typed too much, stopped fully agreeing with myself
@crypticツ If you specify that option, instead of the openssl default options it will use this: lxr.php.net/source/xref/PHP-7.1/ext/openssl/php_openssl.h#41
23:15
When you say rely on the compiler because it does a lot for you, I think of the optimizations done by something that permanently compiles vs a scripting language. Since the scripting language must compile on every run, it will never (probably) have the time to do really heavy optimization
@NikiC see above message, I think it's a really bad idea to maintain a separate list of ciphers - obviously we can't rely on systems to have an up-to-date installation of openssl, but we shouldn't maintain it ourselves. Any opinion?
@Dereleased Unless it can cache it ^_^
@LeviMorrison Absolutely, and it'd be dope if there were a scraight up optimizing compiler that would cache results for use in prod, but still do regular interpretation otherwise
user6061856
Question, should sanitize select elements?
$str = join(array_merge(range('A','Z'),range('a','z'),range('0','9'),['+','/'])); // or whatever that alphabet is.

It'd be super cool if that would just become a flat string in the final cached bytecode copy
23:18
@Dereleased for the average use-case (php as a web scripting language, loaded as a module in a web server or as fpm), the opcode cache is loaded by default - it is compiled once per change in file modified times, per stat()
@Leigh see above
I was typing as you hit enter
happens
there are constant expression optimisations, they don't extend to things like range
they could, but it's a rather special case
@Leigh I know =)
Don't get me wrong, I have been very impressed with a lot of the constant expression optimizations I saw in 5.x => 7
23:19
manpower - people available, benefit gained, you can do the math
I get the concept, I know what you want, but fucked if I can write it
so I guess... manpower with appropriate knowledge, people available, time better spent elsewhere :p
I'm not asking for it to be done, haha
kitten videos aren't gonna watch themselves
no I know
@PaulCrovella Getting to the heart of the real issues
23:22
as a mostly newb to PHP, did I do this right?
public function hasHTML($options)
	{
		if (array_key_exists('html', $options))
		{
			if ($options['html'] === true)
			{
				return true;
			}
		}
		return false;
	}
oh fuck you fixed font
@Leigh If that were one of my cats, there's a 50% chance it would try to fight the screen, 25% chance it would run away, and 25% chance it just goes to sleep right there.
@Tiffany OH GOD NO WHAT DID YOU DO
wait let me read it
it's close enough
public function hasHTML(array $options) { return array_key_exists('html', $options) && (bool)$options['html']; } =P
intent is clear, coding style will get criticism from zealots
I was going to fix the spacing but..... ugh
23:24
@Tiffany I'm curious: did you pick that coding style or did someone else?
user6061856
Question, should sanitize select elements?
brackets on new line?
@Antono yes
That was my major gripe :P
I was going to delete it and repaste it, and fix it properly, but it's too late
also @Dereleased I wouldn't do the casting thing there.
23:25
	public function hasHTML($options) {
		if (array_key_exists('html', $options))
			if ($options['html'] === true)
				return true;
		return false;
	}
^ That is obviously the one true way to write that code.
@LeviMorrison dude, wtf, braces bitch
@Leigh I mean you don't need to... yeah, I'd drop it too.
I just prefer brackets on new line, I know it's not PHP norm, but it's conventional for several other languages.
@Tiffany My vertical space!
god dammit, I keep mixing up brackets and braces.
23:26
(In case it is unclear I was joking about that)
It was unclear
However I'm not joking about this: thanks for using tabs!
I almost hexed you with goto fail
And seriously, I think it should be written like this:
public function hasHTML($options) {
	return array_key_exists('html', $options) && $options['html'] === true;
}
@LeviMorrison I meant to have phpstorm set to convert tabs to spaces. So I could use tab, and it would space four times. Never got around to fixing it.
23:28
I'm still not a fan of array_key_exists - I would never put a null into an array
@Leigh should I use isset()?
Tabs are a superior solution. Don't give in to the spaces zealots.
@Tiffany it depends if you know what's in your array
Where I work my boss prefers 8 spaces per tab, mostly everyone else prefers 4 and I prefer 2.
@Leigh The thing is, $options may not have html in it as a key.
23:29
@LeviMorrison until someone comes in from Perl and, not being used to have barewords for true and false, passes 1. It doesn't work, so they start a smear campaign on twitter. By the time you know what's happened, it's too late. Upwards of 3 people on the internet think you did something silly.
@Tiffany if it may not have the key, isset works, if it may have the key but the value is null, you can't use isset (if the null is important)
I personally try and stay away from null being important
@LeviMorrison 2 is sexy but nobody lets me get away with that. 8 is asinine. Also eff off with your tabs nonsense.
@LeviMorrison so you're all wrong
@Leigh if the key doesn't exist, there won't be a value - null, true, false, otherwise.
because, 4 spaces is 4 spaces
@Tiffany and isset will do the job - but key set and value null, isset wil be false but array_key_exists will be true - you need to know what behaviour you want
23:32
Seems like @Tiffany only wants a true value if the thing is true anyway, so isset() would be fine. I'm tempted to say it'd be faster, but even if that's true, it's probably missing several points.
here's the weird thing. When I write C - totally tabs - PHP, never
@Leigh I can't confirm what future-me will end up doing with this, but present-me says I'll only be setting the key's value to true or false.
@Tiffany What if you decided to support multipart/alternative?
@Tiffany array_key_exists is the safe option, and the intent is clear
@Dereleased that will be future-me's problem.
23:33
if in doubt, pick verbosity
at least others will understand what you were trying to do
(I secretly prefer array_key_exists)
(I have this memory of isset() not working properly with undefined offsets. It's probably an old user-error that I overcorrected for in the past, but, well, here we are)
@Dereleased I'm just writing a method for the class, so I can divvy out work to other areas in the classs instead of having it all in the send_mail function :3
I'm going to use this:
public function hasHTML($options)
{
  return array_key_exists('html', $options) && $options['html'] === true;
}
GOD DAMMIT
7 mins ago, by Levi Morrison
public function hasHTML($options) {
	return array_key_exists('html', $options) && $options['html'] === true;
}
there.
this is how most of us would write it
except i'd use isset
and use 4 spaces
23:35
and hint for array
I know, it's just personal preference to have the brace on a new line cause I'm weird.
and return type bool
@PaulCrovella +1, I'd also hint for array
@Leigh too new, I don't support it =P
I'm on 5.4 :(
@Tiffany It's not that uncommon
@Tiffany well, you can hint at the array then =D
23:37
@Dereleased public function __construct($to, $content, $headers, $options = array())
:3
@Dereleased Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn
!!docs str_rot13
[ str_rot13() ] Perform the rot13 transform on a string
Anybody in Chat got a solid grasp of htaccess ?
23:45
@DMSJax solid as Jello, maybe I can help maybe?
$attachments = $headers['attachments'];
unset($headers['attachments']);
$attachments = (is_array($attachments)) ? $attachments : array();
$head->desk();
What's the issue?
RewriteCond %{REQUEST_URI} ^(.*)[A-z]$ [NC] <--- this is affecting internal calls for resources like IMG SRC, the same as external calls to URL's - is there an htaccess equivalent to REQUEST_URI that applies to only URI calls from a remote request and not the server side calls?
What is the whole rule? Would it be the end of the world to allow through requests that are to existing files?
is there a better way to make a variable an array rather than checking to see if it's an array, and if it isn't, make it an array?
23:52
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [QSA,L]
@DMSJax followed by the rest of your rule
$some_var = $options['some_var']
$some_var = array();
we rebuilt a website that used to have like 80 url's indexed by various search engines that had geo tags in them such as: www.website.com/city1-plumbing www.website.com/city2-electrical-help etc. etc. etc. - i don't even know all the bad URL's that are indexed now - so instead of tracking them all down, we just wanted any URL request from a remote IP (browser) that contained more than the base URL to be redirected to a new sub folder containing the revised site
would that work or is there a better way?
@Tiffany well, specifically what that does is make it an empty array. Then it gets essentially ignored in the following foreach()
@Dereleased blargh.
23:55
@DMSJax The rule I sent you will allow through requests to things that actually exist (like your images and CSS files). After those three lines, add in your rules for routing to the new directory
@Dereleased array $some_var;?
ok, will give it a try, ty
@Tiffany sec
if I remember the sample you sent earlier, after those three lines there's a foreach, right?
@Dereleased yes
    if (array_key_exists('attachments', $headers) && is_array($headers['attachments'])) {
        foreach ($headers['attachments'] as $attachment) {
            do_thing_with_attach($attachment);
        }
    }

    unset($headers['attachments']); // unconditional, why not
23:59
I have a method for hasAttachments($options)

« first day (2286 days earlier)      last day (2887 days later) »