Skip to content

Instantly share code, notes, and snippets.

View bagart's full-sized avatar
🏠
Working from home

BAGArt bagart

🏠
Working from home
View GitHub Profile
@bagart
bagart / php7+.php
Last active November 9, 2018 22:36
array with double key
<?php
class A {
private $omg = 'A';
function dump() {
return get_object_vars($this);
}
}
<?php
function dont_give_me_five(int $start, int $end): int
{
$start_multiple = $start < 0 ? -1 : 1;
$end_multiple = $end < 0 ? -1 : 1;
$zero_value = (int)(
$start_multiple !== $end_multiple
|| false === strpos((string)min(abs($start), abs($end)), '5')
);
@bagart
bagart / DoubleLinked.php
Last active September 2, 2018 20:56
DoubleLinked.php with not numeric keys
<?php declare(strict_types=1);
class DoubleLinkedException extends \Exception
{
}
class WrongNameDoubleLinkedException extends DoubleLinkedException
{
}
<?php
// https://3v4l.org/0Fonp
$x = 1.999999999999999;
$y = 2;
var_dump([
'float: 1.999999999999999' => [
'serilize' => [$x, 'orig' => serialize($x), 'int' => serialize((int)$x), 'round' => serialize(round($x)), $x < 2],
'int' => [(int)$x, (int)$x < 2],
'string'=>[(string)$x, (string)$x < 2],
@bagart
bagart / encapsulation_hack.php
Last active January 31, 2018 09:51
private access in PHP / encapsulation hack
<?php
declare(strict_types=1);
final class A {
private $prop;
public function __construct(DateTime $prop) { $this->prop = $prop; }
public function getProp() { return $this->prop; }
}
$a = new A(new DateTime());