Skip to content

Instantly share code, notes, and snippets.

@raphaeldealmeida
raphaeldealmeida / gist:1839171
Created February 15, 2012 21:39
Funções Anonimas
<?php
function(){
echo 'Olá';
}
$saudacao = function(){
echo 'Olá';
};
@raphaeldealmeida
raphaeldealmeida / gist:1839226
Created February 15, 2012 21:50
utilização clojure
<?php
$cores = array(
array('cor' => 'verde'),
array('cor' => 'vermelho'),
array('cor' => 'amarelo')
);
usort($cores, function($a, $b){
return strcmp($a['cor'], $b['cor']);
}
@raphaeldealmeida
raphaeldealmeida / gist:1839261
Created February 15, 2012 21:55
transação sem closure
<?php
$em->getConnection()->beginTransaction();
try{
//...
$em->persist($user);
$em->flush();
$em->getConnection()->commit();
}catch(Exception $e){
$em->getConnection()->rollback();
@raphaeldealmeida
raphaeldealmeida / gist:1839268
Created February 15, 2012 21:57
transação com closure
<?php
$em->transactional(function($em){
//...
$em->persist($user);
}
@raphaeldealmeida
raphaeldealmeida / operador_ternario.php
Created February 20, 2012 18:02
Operador Ternário PHP 5.3
<?php
$input = 'Raphael';
if(!empty($input)){
echo $input;
}else{
echo 'Vazio' . "\n\r";
}
@raphaeldealmeida
raphaeldealmeida / operador_ternario.php
Created February 20, 2012 18:02
Operador Ternário PHP 5.3
<?php
$input = 'Raphael';
if(!empty($input)){
echo $input;
}else{
echo 'Vazio' . "\n\r";
}
@raphaeldealmeida
raphaeldealmeida / late_static_binding.php
Created February 21, 2012 16:55
PHP 5.3 - Late Static Binding
<?php
class Foo{
protected static function speak(){
echo __METHOD__, "\n\r";
return 'Hi';
}
public static function sayHi(){
//return self::speak(); // PHP 5.2 <=
@raphaeldealmeida
raphaeldealmeida / gist:1885222
Created February 22, 2012 13:44
sem closure
<?php
$lista = array(1, 3, 5, 7, 56, 65, 96, 244, 700, 892);
$filtro100 = function ($x){
return $x > 100;
};
$filtro50 = function ($x){
return $x > 50;
@raphaeldealmeida
raphaeldealmeida / gist:1885226
Created February 22, 2012 13:45
com closure
<?php
$lista = array(1, 3, 5, 7, 56, 65, 96, 244, 700, 892);
function criarFiltro($maiorQue){
return function ($x) use ($maiorQue){
return $x > $maiorQue;
};
}
$filtro100 = criarFiltro(100);
@raphaeldealmeida
raphaeldealmeida / gist:1885228
Created February 22, 2012 13:45
com closure
<?php
$lista = array(1, 3, 5, 7, 56, 65, 96, 244, 700, 892);
function criarFiltro($maiorQue){
return function ($x) use ($maiorQue){
return $x > $maiorQue;
};
}
$filtro100 = criarFiltro(100);