Changing comparison operators to === (identical) which is faster than == (equal)

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7604 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2008-09-14 17:17:49 +00:00
parent 35a2b466de
commit 5658e26e07
8 changed files with 61 additions and 61 deletions

View file

@ -158,7 +158,7 @@ class Cache extends Object {
}
if ($_this->_Engine[$name]->init($settings)) {
if (time() % $_this->_Engine[$name]->settings['probability'] == 0) {
if (time() % $_this->_Engine[$name]->settings['probability'] === 0) {
$_this->_Engine[$name]->gc();
}
return true;

View file

@ -91,7 +91,7 @@ class FileEngine extends CacheEngine {
$this->__File =& new File($this->settings['path'] . DS . 'cake');
}
if (DIRECTORY_SEPARATOR == '\\') {
if (DIRECTORY_SEPARATOR === '\\') {
$this->settings['isWindows'] = true;
}

View file

@ -278,7 +278,7 @@ class ClassRegistry {
$duplicate = false;
if ($_this->isKeySet($alias)) {
$model =& $_this->getObject($alias);
if (is_a($model, $class) || $model->alias == $class) {
if (is_a($model, $class) || $model->alias === $class) {
$duplicate =& $model;
}
unset($model);

View file

@ -219,7 +219,7 @@ class Configure extends Object {
return $contents[0];
} else {
foreach($contents[1] as $item) {
if (substr($item, - strlen($suffix)) == $suffix) {
if (substr($item, - strlen($suffix)) === $suffix) {
if ($extension) {
$items[] = $item;
} else {
@ -469,7 +469,7 @@ class Configure extends Object {
if ($path !== DS) {
$path = rtrim($path, DS);
}
if (empty($path) || $path == '.') {
if (empty($path) || $path === '.') {
continue;
}
$cake = $path . DS . 'cake' . DS;

View file

@ -209,7 +209,7 @@ class Component extends Object {
$this->__settings[$component] = $config;
}
} else {
if ($componentCn == 'SessionComponent') {
if ($componentCn === 'SessionComponent') {
$object->{$component} =& new $componentCn($base);
} else {
$object->{$component} =& new $componentCn();

View file

@ -337,7 +337,7 @@ class Controller extends Object {
foreach ($merge as $var) {
if (isset($appVars[$var]) && !empty($appVars[$var]) && is_array($this->{$var})) {
if ($var == 'components') {
if ($var === 'components') {
$normal = Set::normalize($this->{$var});
$app = Set::normalize($appVars[$var]);
$this->{$var} = Set::merge($normal, $app);
@ -359,7 +359,7 @@ class Controller extends Object {
foreach ($merge as $var) {
if (isset($appVars[$var]) && !empty($appVars[$var]) && is_array($this->{$var})) {
if ($var == 'components') {
if ($var === 'components') {
$normal = Set::normalize($this->{$var});
$app = Set::normalize($appVars[$var]);
$this->{$var} = Set::merge($normal, array_diff_assoc($app, $normal));
@ -600,7 +600,7 @@ class Controller extends Object {
}
foreach ($data as $name => $value) {
if ($name == 'title') {
if ($name === 'title') {
$this->pageTitle = $value;
} else {
if ($two === null && is_array($one)) {
@ -833,7 +833,7 @@ class Controller extends Object {
continue;
}
$fieldOp = strtoupper(trim($fieldOp));
if ($fieldOp == 'LIKE') {
if ($fieldOp === 'LIKE') {
$key = $key.' LIKE';
$value = '%'.$value.'%';
} elseif ($fieldOp && $fieldOp != '=') {
@ -880,7 +880,7 @@ class Controller extends Object {
} elseif (isset($this->{$this->modelClass}) && isset($this->{$this->modelClass}->{$object})) {
$object = $this->{$this->modelClass}->{$object};
}
} elseif (empty($object) || $object == null) {
} elseif (empty($object) || $object === null) {
if (isset($this->{$this->modelClass})) {
$object = $this->{$this->modelClass};
} else {
@ -948,7 +948,7 @@ class Controller extends Object {
if (!in_array($keys[$i], $vars)) {
unset($options[$keys[$i]]);
}
if (empty($whitelist) && ($keys[$i] == 'fields' || $keys[$i] == 'recursive')) {
if (empty($whitelist) && ($keys[$i] === 'fields' || $keys[$i] === 'recursive')) {
unset($options[$keys[$i]]);
} elseif (!empty($whitelist) && !in_array($keys[$i], $whitelist)) {
unset($options[$keys[$i]]);
@ -987,7 +987,7 @@ class Controller extends Object {
}
$pageCount = intval(ceil($count / $limit));
if ($page == 'last' || $page >= $pageCount) {
if ($page === 'last' || $page >= $pageCount) {
$options['page'] = $page = $pageCount;
} elseif (intval($page) < 1) {
$options['page'] = $page = 1;

View file

@ -318,7 +318,7 @@ class Router extends Object {
* @static
*/
function writeRoute($route, $default, $params) {
if (empty($route) || ($route == '/')) {
if (empty($route) || ($route === '/')) {
return array('/^[\/]*$/', array());
}
$names = array();
@ -342,7 +342,7 @@ class Router extends Object {
$parsed[] = '(?:/([^\/]+))?';
}
$names[] = $r[1];
} elseif ($element == '*') {
} elseif ($element === '*') {
$parsed[] = '(?:/(.*))?';
} else if ($namedParam && preg_match_all('/(?!\\\\):([a-z_0-9]+)/i', $element, $matches)) {
$matchCount = count($matches[1]);
@ -353,11 +353,11 @@ class Router extends Object {
$element = substr($element, $pos + strlen($name) + 1);
$after = null;
if ($i + 1 == $matchCount && $element) {
if ($i + 1 === $matchCount && $element) {
$after = preg_quote($element);
}
if ($i == 0) {
if ($i === 0) {
$before = '/' . $before;
}
$before = preg_quote($before, '#');
@ -419,7 +419,7 @@ class Router extends Object {
extract($_this->__parseExtension($url));
foreach ($_this->routes as $i => $route) {
if (count($route) == 3) {
if (count($route) === 3) {
if (!list($pattern, $names) = $_this->writeRoute($route[0], $route[1], $route[2])) {
unset($_this->routes[$i]);
continue;
@ -508,7 +508,7 @@ class Router extends Object {
return false;
} else {
foreach ($defaults as $key => $val) {
if ($key{0} == '[' && preg_match('/^\[(\w+)\]$/', $key, $header)) {
if ($key{0} === '[' && preg_match('/^\[(\w+)\]$/', $key, $header)) {
if (isset($_this->__headerMap[$header[1]])) {
$header = $_this->__headerMap[$header[1]];
} else {
@ -520,7 +520,7 @@ class Router extends Object {
}
$h = false;
foreach ($val as $v) {
if (env(strtoupper($header)) == $v) {
if (env(strtoupper($header)) === $v) {
$h = true;
}
}
@ -544,7 +544,7 @@ class Router extends Object {
$_this =& Router::getInstance();
if ($_this->__parseExtensions) {
if (preg_match('/\.[0-9a-zA-Z]*$/', $url, $match) == 1) {
if (preg_match('/\.[0-9a-zA-Z]*$/', $url, $match) === 1) {
$match = substr($match[0], 1);
if (empty($_this->__validExtensions)) {
$url = substr($url, 0, strpos($url, '.' . $match));
@ -705,7 +705,7 @@ class Router extends Object {
*/
function promote($which = null) {
$_this =& Router::getInstance();
if ($which == null) {
if ($which === null) {
$which = count($_this->routes) - 1;
}
if (!isset($_this->routes[$which])) {
@ -762,7 +762,7 @@ class Router extends Object {
$base = null;
unset($url['base']);
}
if (isset($url['full_base']) && $url['full_base'] == true) {
if (isset($url['full_base']) && $url['full_base'] === true) {
$full = true;
unset($url['full_base']);
}
@ -775,7 +775,7 @@ class Router extends Object {
unset($url['#']);
}
if (empty($url['action'])) {
if (empty($url['controller']) || $params['controller'] == $url['controller']) {
if (empty($url['controller']) || $params['controller'] === $url['controller']) {
$url['action'] = $params['action'];
} else {
$url['action'] = 'index';
@ -807,7 +807,7 @@ class Router extends Object {
$match = false;
foreach ($_this->routes as $i => $route) {
if (count($route) == 3) {
if (count($route) === 3) {
if (!list($pattern, $names) = $_this->writeRoute($route[0], $route[1], $route[2])) {
unset($_this->routes[$i]);
continue;
@ -840,9 +840,9 @@ class Router extends Object {
// Remove this once parsed URL parameters can be inserted into 'pass'
for ($i = 0; $i < $count; $i++) {
if ($i == 0 && is_numeric($keys[$i]) && in_array('id', $keys)) {
if ($i === 0 && is_numeric($keys[$i]) && in_array('id', $keys)) {
$args[0] = $url[$keys[$i]];
} elseif (is_numeric($keys[$i]) || $keys[$i] == 'id') {
} elseif (is_numeric($keys[$i]) || $keys[$i] === 'id') {
$args[] = $url[$keys[$i]];
} else {
$named[$keys[$i]] = $url[$keys[$i]];
@ -855,7 +855,7 @@ class Router extends Object {
$url['action'] = str_replace($_this->__admin . '_', '', $url['action']);
}
if (empty($named) && empty($args) && (!isset($url['action']) || $url['action'] == 'index')) {
if (empty($named) && empty($args) && (!isset($url['action']) || $url['action'] === 'index')) {
$url['action'] = null;
}
@ -895,7 +895,7 @@ class Router extends Object {
$path['here'] = '/';
}
$output = $path['here'];
} elseif (substr($url, 0, 1) == '/') {
} elseif (substr($url, 0, 1) === '/') {
$output = $base . $url;
} else {
$output = $base . '/';
@ -912,7 +912,7 @@ class Router extends Object {
if ($full) {
$output = FULL_BASE_URL . $output;
}
if (!empty($extension) && substr($output, -1) == '/') {
if (!empty($extension) && substr($output, -1) === '/') {
$output = substr($output, 0, -1);
}
@ -985,7 +985,7 @@ class Router extends Object {
if (!empty($routeParams)) {
$filled = array_intersect_key($url, array_combine($routeParams, array_keys($routeParams)));
$isFilled = (array_diff($routeParams, array_keys($filled)) == array());
$isFilled = (array_diff($routeParams, array_keys($filled)) === array());
if (!$isFilled && empty($params)) {
return false;
}
@ -1008,7 +1008,7 @@ class Router extends Object {
}
}
} else {
if (empty($required) && $defaults['plugin'] == $url['plugin'] && $defaults['controller'] == $url['controller'] && $defaults['action'] == $url['action']) {
if (empty($required) && $defaults['plugin'] === $url['plugin'] && $defaults['controller'] === $url['controller'] && $defaults['action'] === $url['action']) {
return Router::__mapRoute($route, array_merge($url, compact('pass', 'named', 'prefix')));
}
return false;
@ -1230,7 +1230,7 @@ class Router extends Object {
$pos1 = strrpos($base, '/');
$char = strlen($base) - 1;
if ($pos1 == $char) {
if ($pos1 === $char) {
$base = substr($base, 0, $char);
}
}
@ -1310,7 +1310,7 @@ class Router extends Object {
}
$rules = $_this->named['rules'];
if (isset($options['named'])) {
$greedy = isset($options['greedy']) && $options['greedy'] == true;
$greedy = isset($options['greedy']) && $options['greedy'] === true;
foreach ((array)$options['named'] as $key => $val) {
if (is_numeric($key)) {
$rules[$val] = true;

View file

@ -129,7 +129,7 @@ class Set extends Object {
$class = $tmp;
}
if (empty($val) || $val == null) {
if (empty($val)) {
return null;
}
return Set::__map($val, $class);
@ -189,7 +189,7 @@ class Set extends Object {
}
$out[$key] = Set::__map($value, $class);
if (is_object($out[$key])) {
if ($primary !== true && is_array($value) && Set::countDim($value, true) == 2) {
if ($primary !== true && is_array($value) && Set::countDim($value, true) === 2) {
$out[$key]->_name_ = $primary;
}
}
@ -360,10 +360,10 @@ class Set extends Object {
* @access public
*/
function extract($path, $data = null, $options = array()) {
if (empty($data) && is_string($path) && $path{0} == '/') {
if (empty($data) && is_string($path) && $path{0} === '/') {
return array();
}
if (is_string($data) && $data{0} == '/') {
if (is_string($data) && $data{0} === '/') {
$tmp = $path;
$path = $data;
$data = $tmp;
@ -371,7 +371,7 @@ class Set extends Object {
if (is_array($path) || empty($data) || is_object($path) || empty($path)) {
return Set::classicExtract($path, $data);
}
if ($path == '/') {
if ($path === '/') {
return $data;
}
$contexts = $data;
@ -396,7 +396,7 @@ class Set extends Object {
if (!isset($context['trace'])) {
$context = array('trace' => array(), 'item' => $context, 'key' => null);
}
if ($token == '..') {
if ($token === '..') {
$parent = join('/', $context['trace']).'['.($key+1).']';
$context['item'] = Set::extract($parent, $data);
$context['key'] = array_pop($context['trace']);
@ -406,7 +406,7 @@ class Set extends Object {
}
$match = false;
if ($token == '@*' && is_array($context['item'])) {
if ($token === '@*' && is_array($context['item'])) {
$matches[] = array(
'trace' => am($context['trace'], $key),
'key' => $key,
@ -477,12 +477,12 @@ class Set extends Object {
return !!Set::extract($conditions, $data);
}
foreach ($conditions as $condition) {
if ($condition == ':last') {
if ($condition === ':last') {
if ($i != $length) {
return false;
}
continue;
} elseif ($condition == ':first') {
} elseif ($condition === ':first') {
if ($i != 1) {
return false;
}
@ -505,19 +505,19 @@ class Set extends Object {
return false;
}
$val = $data[$key];
if ($op == '=' && $expected && $expected{0} == '/') {
if ($op === '=' && $expected && $expected{0} === '/') {
return preg_match($expected, $val);
} elseif ($op == '=' && $val != $expected) {
} elseif ($op === '=' && $val != $expected) {
return false;
} elseif ($op == '!=' && $val == $expected) {
} elseif ($op === '!=' && $val == $expected) {
return false;
} elseif ($op == '>' && $val <= $expected) {
} elseif ($op === '>' && $val <= $expected) {
return false;
} elseif ($op == '<' && $val >= $expected) {
} elseif ($op === '<' && $val >= $expected) {
return false;
} elseif ($op == '<=' && $val > $expected) {
} elseif ($op === '<=' && $val > $expected) {
return false;
} elseif ($op == '>=' && $val < $expected) {
} elseif ($op === '>=' && $val < $expected) {
return false;
}
}
@ -555,13 +555,13 @@ class Set extends Object {
}
foreach ($path as $i => $key) {
if (is_numeric($key) && intval($key) > 0 || $key == '0') {
if (is_numeric($key) && intval($key) > 0 || $key === '0') {
if (isset($data[intval($key)])) {
$data = $data[intval($key)];
} else {
return null;
}
} elseif ($key == '{n}') {
} elseif ($key === '{n}') {
foreach ($data as $j => $val) {
if (is_int($j)) {
$tmpPath = array_slice($path, $i + 1);
@ -573,7 +573,7 @@ class Set extends Object {
}
}
return $tmp;
} elseif ($key == '{s}') {
} elseif ($key === '{s}') {
foreach ($data as $j => $val) {
if (is_string($j)) {
$tmpPath = array_slice($path, $i + 1);
@ -625,10 +625,10 @@ class Set extends Object {
$_list =& $list;
foreach ($path as $i => $key) {
if (is_numeric($key) && intval($key) > 0 || $key == '0') {
if (is_numeric($key) && intval($key) > 0 || $key === '0') {
$key = intval($key);
}
if ($i == count($path) - 1) {
if ($i === count($path) - 1) {
$_list[$key] = $data;
} else {
if (!isset($_list[$key])) {
@ -657,10 +657,10 @@ class Set extends Object {
$_list =& $list;
foreach ($path as $i => $key) {
if (is_numeric($key) && intval($key) > 0 || $key == '0') {
if (is_numeric($key) && intval($key) > 0 || $key === '0') {
$key = intval($key);
}
if ($i == count($path) - 1) {
if ($i === count($path) - 1) {
unset($_list[$key]);
} else {
if (!isset($_list[$key])) {
@ -688,10 +688,10 @@ class Set extends Object {
}
foreach ($path as $i => $key) {
if (is_numeric($key) && intval($key) > 0 || $key == '0') {
if (is_numeric($key) && intval($key) > 0 || $key === '0') {
$key = intval($key);
}
if ($i == count($path) - 1) {
if ($i === count($path) - 1) {
return (is_array($data) && array_key_exists($key, $data));
} else {
if (!is_array($data) || !array_key_exists($key, $data)) {
@ -989,9 +989,9 @@ class Set extends Object {
$result = Set::__flatten(Set::extract($data, $path));
list($keys, $values) = array(Set::extract($result, '{n}.id'), Set::extract($result, '{n}.value'));
if ($dir == 'asc') {
if ($dir === 'asc') {
$dir = SORT_ASC;
} elseif ($dir == 'desc') {
} elseif ($dir === 'desc') {
$dir = SORT_DESC;
}
array_multisort($values, $dir, $keys, $dir);