Skip to content

Instantly share code, notes, and snippets.

View glennpratt's full-sized avatar

Glenn Pratt glennpratt

View GitHub Profile
± |donate ✓| → php -a
Interactive shell
php > $truck = new stdClass();
php > $truck->var = TRUE;
php > if ($truck->non) {
php { echo 'Yo';
php { }
PHP Notice: Undefined property: stdClass::$non in php shell code on line 1
○ → sudo pear list -a
Installed packages, channel __uri:
==================================
(no packages installed)
Installed packages, channel components.ez.no:
=============================================
Package Version State
Base 1.8 stable
ConsoleTools 1.6.1 stable
<?php
require_once trim(`which phpunit`);
Fatal error: Uncaught exception 'ErrorException' with message 'Notice: Undefined variable: undefined_var in /srv/www/current/www/sites/all/modules/allplayers/misc/misc.module line 14' in /srv/www/current/www/sites/all/libraries/Symfony/src/Symfony/Component/HttpKernel/Debug/ErrorHandler.php:65
Stack trace:
#0 /srv/www/current/www/sites/all/modules/allplayers/misc/misc.module(14): Symfony\Component\HttpKernel\Debug\ErrorHandler->handle(8, 'Undefined varia...', '/srv/www/curren...', 14, Array)
#1 [internal function]: misc_boot()
#2 /srv/www/current/www/includes/module.inc(512): call_user_func_array('misc_boot', Array)
#3 /srv/www/current/www/includes/bootstrap.inc(748): module_invoke('misc', 'boot')
#4 /srv/www/current/www/includes/bootstrap.inc(1511): bootstrap_invoke_all('boot')
#5 /srv/www/current/www/includes/bootstrap.inc(1411): _drupal_bootstrap(5)
<?php
/**
* This is untested.
*/
class PermissionTest {
/**
* @expectedException PHPUnit_Assertion_Failed
*/
public function testSomePerm() {
<?php
while (apci_auto_schedule_events_batch_continue()) {
// Cleanup
db_query('UPDATE queue SET expire = 0');
drupal_queue_cron_run();
}
php > $tz = new DateTimeZone('America/Chicago');
php > var_dump($tz->getLocation());
array(4) {
["country_code"]=>
string(2) "US"
["latitude"]=>
float(41.85)
["longitude"]=>
float(-87.65)
["comments"]=>
<?php
function test($x, $y, $z) {
var_dump(($x || $y) && ($z || $y));
var_dump(($x && $z) || $y);
}
test(TRUE, TRUE, TRUE);
test(TRUE, FALSE, TRUE);
test(TRUE, TRUE, FALSE);
test(FALSE, FALSE, TRUE);

Use namespaced, static methods for hooks instead of functions.

<?php
example_boot();
// Becomes
Drupal\Module\Example\Hook\System::boot();

example_menu();
// Becomes
○ → php -a
Interactive shell
php > $var = array();
php > $var[NULL] = "NULL";
php > $var[0] = "0";
php > $var[FALSE] = "FALSE";
php > $var[''] = "''";
php > var_dump($var);
array(2) {