Created
December 1, 2011 15:16
-
-
Save theUniC/1417486 to your computer and use it in GitHub Desktop.
PHP Best Practices - engineering.emagister.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Se debe cambiar debidamente el path al directorio dónde PHP | |
# escanea en busca de archivos ini. | |
pecl install apc | |
echo "extension=apc.so" >> /etc/php5/conf.d/apc.ini |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$string = ' Gracias por venir!'; | |
printf('Hola a todos' . $string); // Lento | |
echo 'Hola a todos' , $string; // Rápido |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$myDb = new PDO(...); | |
function getRowSet() | |
{ | |
global $myDb; | |
return $myDb->query('SELECT ...'); | |
} | |
function getAnotherRowSet() | |
{ | |
global $myDb; | |
$myDb = new PDO(...); | |
return $myDb->query('SELECT ...'); | |
} | |
$rowSet = getRowSet(); | |
$anotherRowSet = getAnotherRowSet(); | |
$thirdRowSet = getRowSet(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (array_key_exists('submit-btn', $_POST)) { | |
// Vulnerabilidad muy muy obvia | |
// a modo de ejemplo | |
$firstName = $_POST['firstname']; | |
$path = __DIR__ . "/user/profiles/$firstname.txt"; | |
@readfile($path); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Registry extends ArrayObject | |
{ | |
private $_instance; | |
private function __construct() {} | |
public function __clone() | |
{ | |
throw new Exception('This object cannot be clonned!'); | |
} | |
public static function getInstance() | |
{ | |
if (null === static::$_instance) { | |
static::$_instance = new static(); | |
} | |
return static::$_instance; | |
} | |
} | |
Registry::getInstance()->offsetSet('test', 'stringTest'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$string = 'Hola a todos!'; | |
if (strpos($string, 'H')) { | |
$string .= ' Gracias por venir!'; | |
} | |
echo $string; // Imprimirá "Hola a todos!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$string = 'Hola a todos!'; | |
if (false !== strpos($string, 'H')) { | |
$string .= ' Gracias por venir!'; | |
} | |
echo $string; // Imprimirá "Hola a todos! Gracias por venir!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment