View add.php
<?php | |
function add(float $a, float $b): float { | |
return $a + $b; | |
} |
View recursive-array-modification.php
<?php | |
$data = array('foo', '', 'bar'); | |
array_walk_recursive($data, function (&$value, $key) { | |
if ($value === '') { | |
$value = null; | |
} | |
}); | |
var_dump($data); |
View ImageMagickCommandLineProcessor.php
<?php | |
/** | |
* ImagickProcessor | |
* | |
* @author Frank Liepert <contact@frank-liepert.de> | |
*/ | |
class ImageMagickCommandLineProcessor | |
{ | |
/** @type string $error */ | |
protected $error; |
View pdflib_pcos_colorspace.php
<?php | |
try { | |
$pdflib = new PDFlib; | |
$colorspace = new Colorspace($pdflib); | |
print_r ($colorspace->analyze('test.pdf')); | |
} catch (PDFlibException $e) { | |
print_r ($e); | |
} | |
class Colorspace |
View signatures.php
<?php | |
class Parents | |
{ | |
public function doSomething($x) | |
{ | |
print $x; | |
} | |
} | |
class ChildA extends Parents |
View reset.php
<?php | |
class Foo | |
{ | |
protected $bar; | |
public function __construct() | |
{ | |
$this->bar = 'bar'; | |
} | |
View config.php
<?php | |
$container->addDefinition('AnotherService', new Definition('Application\Service\AnotherService')) | |
->setter('setFoo', 'Foo'); | |
$container->addDefinition('ExampleService', new Definition('Application\Service\ExampleService')) | |
->constructor(array('@AnotherService')); | |
$container->addDefinition('Session', new Definition('lib\Session\Session')); | |
$container->addDefinition('SessionAwareInterface', new Definition('lib\Session\SessionAwareInterface')) |
View htmlspecialchars-types.php
<?php | |
$string = 'foo'; | |
var_dump(htmlspecialchars($string)); | |
// string(3) "foo" | |
$integer = 1; | |
var_dump(htmlspecialchars($integer)); | |
// string(1) "1" | |
$float = 1.2; |
View gist:5330082
<?php | |
function getInputValueByName($name, $data) { | |
if (strpos($name, '[]') !== false) { | |
$name = str_replace('[]', '', $name); | |
} | |
$parts = explode('[', $name); | |
$value = $data; | |
foreach ($parts as $part) { | |
$part = rtrim($part, ']'); |