Skip to content

Instantly share code, notes, and snippets.

@Seldaek
Created December 15, 2010 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Seldaek/742293 to your computer and use it in GitHub Desktop.
Save Seldaek/742293 to your computer and use it in GitHub Desktop.
forms
<?php
class Field {
protected static $options = array('a', 'b');
public static function getOptions() {
return static::$options;
}
public static $options2 = array('a', 'b');
}
class SubField extends Field {
protected static $options = array('c');
public static $options2 = array('c');
}
class SubField2 extends Field {
}
var_dump(Field::getOptions());
var_dump(SubField::getOptions());
var_dump(SubField2::getOptions());
if (isset(Field::$options2)) {
var_dump(Field::$options2);
}
if (isset(SubField::$options2)) {
var_dump(SubField::$options2);
}
if (isset(SubField2::$options2)) {
var_dump(SubField2::$options2);
}
$start = microtime(true);
for ($i = 0; $i < 100000; $i++) {
Field::getOptions();
SubField::getOptions();
SubField2::getOptions();
}
var_dump(microtime(true) - $start);
$start = microtime(true);
for ($i = 0; $i < 100000; $i++) {
if (isset(Field::$options2)) {
Field::$options2;
}
if (isset(SubField::$options2)) {
SubField::$options2;
}
if (isset(SubField2::$options2)) {
SubField2::$options2;
}
}
var_dump(microtime(true) - $start);
array
0 => string 'a' (length=1)
1 => string 'b' (length=1)
array
0 => string 'c' (length=1)
array
0 => string 'a' (length=1)
1 => string 'b' (length=1)
array
0 => string 'a' (length=1)
1 => string 'b' (length=1)
array
0 => string 'c' (length=1)
array
0 => string 'a' (length=1)
1 => string 'b' (length=1)
float 1.0107119083405
float 0.22810196876526
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment