Skip to content

Instantly share code, notes, and snippets.

@luisartola
Created July 2, 2012 15:51
Show Gist options
  • Save luisartola/3033912 to your computer and use it in GitHub Desktop.
Save luisartola/3033912 to your computer and use it in GitHub Desktop.
paranas php
function doSomething(callable $x) {
return $x();
}
doSomething(function () { });
doSomething("function_name");
doSomething(['class', 'staticMethodName']);
doSomething([$object, 'methodName']);
doSomething($invokableObject);
function doSomething(callable $x) {
return $x();
}
doSomething(function () { });
doSomething("function_name");
doSomething(['class', 'staticMethodName']);
doSomething([$object, 'methodName']);
doSomething($invokableObject);
class foo {
function test() {
echo "Foo walks into a bar...";
}
function anonFunc() {
return function() { $this->test(); };
} }
class bar {
public function __construct(foo $o) {
$a = $o->anonFunc(); $a();
}
}
new bar(new foo); // prints “Foo walks into a bar...”
inyección php unclebob
Implementar el articulo de unclebob con pimple
<?php
class tralari {
public function soyTrait(){
echo "puedo volar!";
return $this;
}
}
$pruebas = new tralari();
$pruebas->coco = "pepo";
$pruebas->pepo = "coco";
$pruebas->soyTrait();
//print_r(array_filter((array)$pruebas, function($n) { return $n == "pepo";}));
class User extends ArrayObject{
function filter(Closure $closure){
var_dump($this->storage);
}
}
$user = new User();
var_dump($user);
die();
$user->filter(function(){});
$user->coco = "pepo";
$user[0] = "tralarelo";
$popo = array_filter((array)$user, function($n) {return $n == "tralarelo";});
var_dump($popo);
die();
cuando haces esto te devuelve una stdclass!!
$row = $this->getAdapter()->fetchRow($sql);
esto funciona
$soyunstring{3}
$stdClass->method = function() {tralari tralara}
$stdClass->method();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment