Skip to content

Instantly share code, notes, and snippets.

@shanethehat
shanethehat / Switcher.php
Created February 12, 2014 07:33
The var_dump on line 69 of switch.php returns an instance of Prophecy\Prophecy\MethodProphecy instead of the value '2'. This seems to be caused by the way phpspec unwraps the iterator created in spec.php line 26.
class Foo_Page_Block_Switch extends Mage_Page_Block_Switch
{
/**
* Application
* @var Mage_Core_Model_App
*/
private $_app;
/**
* Staging Collection

Keybase proof

I hereby claim:

  • I am shanethehat on github.
  • I am shanethehat (https://keybase.io/shanethehat) on keybase.
  • I have a public key whose fingerprint is 4080 3FA2 78D3 06B5 EEFF BB7E 756F D21E 6E71 2C52

To claim this, I am signing this object:

<?php
/**
* SplClassLoader implementation that implements the technical interoperability
* standards for PHP 5.3 namespaces and class names.
*
* http://groups.google.com/group/php-standards/web/final-proposal
*
* // Example which loads classes for the Doctrine Common package in the
* // Doctrine\Common namespace.
div#container {
width:500px;
}
ul#navList li {
width:100px;
margin-right:25px;
text-align:center;
}
li.last {
margin-right:0px;
<div id="container">
<ul id=navList">
<li>Nav Item 1</li>
<li>Nav Item 2</li>
<li>Nav Item 3</li>
<li>Nav Item 4</li>
<li class="last">Nav Item 5</li>
</ul>
</div>
[**Please, don't use `mysql_*` functions in new code**](http://bit.ly/phpmsql). They are no longer maintained [and are officially deprecated](http://j.mp/XqV7Lp). See the [**red box**](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. If you choose PDO, [here is a good tutorial](http://j.mp/PoWehJ).

Please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.

@shanethehat
shanethehat / test_null.php
Last active December 15, 2015 13:29
Demonstration of the speed difference between calling is_null and using a comparison operator.
<?php
function runTestFunction($name, Callable $function) {
$startTime = microtime(true);
for ($i = 0; $i < 10000000; $i++) {
$function();
}
$endTime = microtime(true);
echo $name . ' took ' . ($endTime - $startTime);
echo PHP_EOL;
array (size=1)
0 =>
object(Drupal\user\Plugin\Core\Entity\User)[1005]
public 'uid' => int 0
public 'uuid' => string '1489b0ea-0874-4220-9409-9b3206f6e4d4' (length=36)
public 'name' => string 'Me' (length=2)
public 'pass' => null
public 'mail' => string '' (length=0)
public 'theme' => null
public 'signature' => null
/**
* Implements hook_library_info_alter()
*/
function slukphp_library_info_alter(&$libraries, $module) {
if ($module == 'system' && isset($libraries['modernizr'])) {
$file = drupal_get_path('theme', 'slukphp') . '/'; //filename relative to .theme file
$libraries['modernizr']['version'] = '2.6.2';
$libraries['modernizr']['js'] = array(
$file => array(
'every_page' => 1,
@shanethehat
shanethehat / assignment-test.php
Last active December 16, 2015 23:49
Speed test assigning to local variable vs reference variable vs array index
<?php
$arr = array('a' => 'c');
$arr2 = array('a' => 'c');
$ref = &$arr2['a'];
$startArr = microtime(true);
foreach (range(1,10000) as $i) {
$arr['a'] = 'b';
}