diff --git a/build/controllers/PhpDocController.php b/build/controllers/PhpDocController.php
index dca2156b61..c31270101d 100644
--- a/build/controllers/PhpDocController.php
+++ b/build/controllers/PhpDocController.php
@@ -170,7 +170,7 @@ class PhpDocController extends Controller
$namespaceLine = '';
$contentAfterNamespace = false;
foreach($lines as $i => $line) {
- if (substr(trim($line), 0, 9) === 'namespace') {
+ if (substr_compare(trim($line), 'namespace', 0, 9) === 0) {
$namespace = $i;
$namespaceLine = trim($line);
} elseif ($namespace !== false && trim($line) !== '') {
@@ -275,13 +275,13 @@ class PhpDocController extends Controller
// TODO move these checks to different action
$lines = explode("\n", $newDoc);
- if (trim($lines[1]) == '*' || substr(trim($lines[1]), 0, 3) == '* @') {
+ if (trim($lines[1]) == '*' || substr_compare(trim($lines[1]), '* @', 0, 3) === 0) {
$this->stderr("[WARN] Class $className has no short description.\n", Console::FG_YELLOW, Console::BOLD);
}
foreach ($lines as $line) {
- if (substr(trim($line), 0, 9) == '* @since ') {
+ if (substr_compare(trim($line), '* @since ', 0, 9) === 0) {
$seenSince = true;
- } elseif (substr(trim($line), 0, 10) == '* @author ') {
+ } elseif (substr_compare(trim($line), '* @author ', 0, 10) === 0) {
$seenAuthor = true;
}
}
@@ -350,13 +350,13 @@ class PhpDocController extends Controller
$propertyPart = false;
$propertyPosition = false;
foreach ($lines as $i => $line) {
- if (substr(trim($line), 0, 12) == '* @property ') {
+ if (substr_compare(trim($line), '* @property ', 0, 12) === 0) {
$propertyPart = true;
} elseif ($propertyPart && trim($line) == '*') {
$propertyPosition = $i;
$propertyPart = false;
}
- if (substr(trim($line), 0, 10) == '* @author ' && $propertyPosition === false) {
+ if (substr_compare(trim($line), '* @author ', 0, 10) === 0 && $propertyPosition === false) {
$propertyPosition = $i - 1;
$propertyPart = false;
}
diff --git a/extensions/apidoc/models/TypeDoc.php b/extensions/apidoc/models/TypeDoc.php
index 12bbc5753c..80d31d91ee 100644
--- a/extensions/apidoc/models/TypeDoc.php
+++ b/extensions/apidoc/models/TypeDoc.php
@@ -46,7 +46,7 @@ class TypeDoc extends BaseDoc
}
}
}
- if (substr($subjectName, -2, 2) == '()') {
+ if (substr_compare($subjectName, '()', -2, 2) === 0) {
return null;
}
if ($this->properties === null) {
diff --git a/extensions/apidoc/renderers/BaseRenderer.php b/extensions/apidoc/renderers/BaseRenderer.php
index 86ab186d0b..812cfd924a 100644
--- a/extensions/apidoc/renderers/BaseRenderer.php
+++ b/extensions/apidoc/renderers/BaseRenderer.php
@@ -72,7 +72,7 @@ abstract class BaseRenderer extends Component
foreach ($types as $type) {
$postfix = '';
if (!is_object($type)) {
- if (substr($type, -2, 2) == '[]') {
+ if (substr_compare($type, '[]', -2, 2) === 0) {
$postfix = '[]';
$type = substr($type, 0, -2);
}
diff --git a/extensions/apidoc/templates/html/views/seeAlso.php b/extensions/apidoc/templates/html/views/seeAlso.php
index 5d6e3774c5..12d83c12fc 100644
--- a/extensions/apidoc/templates/html/views/seeAlso.php
+++ b/extensions/apidoc/templates/html/views/seeAlso.php
@@ -23,7 +23,7 @@ if (empty($see)) {
} else {
echo '
See also:
';
foreach ($see as $ref) {
- if (substr($ref, -1, 1) != '>') {
+ if (substr_compare($ref, '>', -1, 1)) {
$ref .= '.';
}
echo "- $ref
";
diff --git a/extensions/authclient/OAuth1.php b/extensions/authclient/OAuth1.php
index 2d7841010d..356a71b3a3 100644
--- a/extensions/authclient/OAuth1.php
+++ b/extensions/authclient/OAuth1.php
@@ -349,7 +349,7 @@ class OAuth1 extends BaseOAuth
$headerParams[] = 'realm="' . rawurlencode($realm) . '"';
}
foreach ($params as $key => $value) {
- if (substr($key, 0, 5) != 'oauth') {
+ if (substr_compare($key, 'oauth', 0, 5)) {
continue;
}
$headerParams[] = rawurlencode($key) . '="' . rawurlencode($value) . '"';
diff --git a/extensions/authclient/OpenId.php b/extensions/authclient/OpenId.php
index b26e5fe619..27839d7204 100644
--- a/extensions/authclient/OpenId.php
+++ b/extensions/authclient/OpenId.php
@@ -761,7 +761,7 @@ class OpenId extends BaseClient implements ClientInterface
} else {
// 'ax' prefix is either undefined, or points to another extension, so we search for another prefix
foreach ($this->data as $key => $value) {
- if (substr($key, 0, strlen('openid_ns_')) == 'openid_ns_' && $value == 'http://openid.net/srv/ax/1.0') {
+ if (substr_compare($key, 'openid_ns_', 0, 10) === 0 && $value == 'http://openid.net/srv/ax/1.0') {
$alias = substr($key, strlen('openid_ns_'));
break;
}
@@ -775,7 +775,7 @@ class OpenId extends BaseClient implements ClientInterface
$attributes = [];
foreach ($this->data as $key => $value) {
$keyMatch = 'openid_' . $alias . '_value_';
- if (substr($key, 0, strlen($keyMatch)) != $keyMatch) {
+ if (substr_compare($key, $keyMatch, 0, strlen($keyMatch))) {
continue;
}
$key = substr($key, strlen($keyMatch));
@@ -802,7 +802,7 @@ class OpenId extends BaseClient implements ClientInterface
$sregToAx = array_flip($this->axToSregMap);
foreach ($this->data as $key => $value) {
$keyMatch = 'openid_sreg_';
- if (substr($key, 0, strlen($keyMatch)) != $keyMatch) {
+ if (substr_compare($key, $keyMatch, 0, strlen($keyMatch))) {
continue;
}
$key = substr($key, strlen($keyMatch));
diff --git a/extensions/gii/generators/model/Generator.php b/extensions/gii/generators/model/Generator.php
index 534dfe6cb9..aeb168a81a 100644
--- a/extensions/gii/generators/model/Generator.php
+++ b/extensions/gii/generators/model/Generator.php
@@ -478,7 +478,7 @@ class Generator extends \yii\gii\Generator
if ($this->isReservedKeyword($this->modelClass)) {
$this->addError('modelClass', 'Class name cannot be a reserved PHP keyword.');
}
- if (substr($this->tableName, -1) !== '*' && $this->modelClass == '') {
+ if (substr_compare($this->tableName, '*', -1) && $this->modelClass == '') {
$this->addError('modelClass', 'Model Class cannot be blank if table name does not end with asterisk.');
}
}
diff --git a/extensions/gii/generators/module/Generator.php b/extensions/gii/generators/module/Generator.php
index 353afe67cd..270454865c 100644
--- a/extensions/gii/generators/module/Generator.php
+++ b/extensions/gii/generators/module/Generator.php
@@ -146,7 +146,7 @@ EOD;
if (strpos($this->moduleClass, '\\') === false || Yii::getAlias('@' . str_replace('\\', '/', $this->moduleClass), false) === false) {
$this->addError('moduleClass', 'Module class must be properly namespaced.');
}
- if (substr($this->moduleClass, -1, 1) == '\\') {
+ if (substr_compare($this->moduleClass, '\\', -1, 1) === 0) {
$this->addError('moduleClass', 'Module class name must not be empty. Please enter a fully qualified class name. e.g. "app\\modules\\admin\\Module".');
}
}
diff --git a/extensions/sphinx/gii/model/Generator.php b/extensions/sphinx/gii/model/Generator.php
index 07664db2bb..c7fb10ef5f 100644
--- a/extensions/sphinx/gii/model/Generator.php
+++ b/extensions/sphinx/gii/model/Generator.php
@@ -266,7 +266,7 @@ class Generator extends \yii\gii\Generator
if ($this->isReservedKeyword($this->modelClass)) {
$this->addError('modelClass', 'Class name cannot be a reserved PHP keyword.');
}
- if (substr($this->indexName, -1) !== '*' && $this->modelClass == '') {
+ if (substr_compare($this->indexName, '*', -1) && $this->modelClass == '') {
$this->addError('modelClass', 'Model Class cannot be blank if table name does not end with asterisk.');
}
}
diff --git a/framework/console/controllers/MessageController.php b/framework/console/controllers/MessageController.php
index 519a09bfe2..0f03d03f42 100644
--- a/framework/console/controllers/MessageController.php
+++ b/framework/console/controllers/MessageController.php
@@ -333,7 +333,7 @@ class MessageController extends Controller
ksort($translated);
foreach ($translated as $message => $translation) {
if (!isset($merged[$message]) && !isset($todo[$message]) && !$removeUnused) {
- if (substr($translation, 0, 2) === '@@' && substr($translation, -2) === '@@') {
+ if (substr_compare($translation, '@@', 0, 2) === 0 && substr_compare($translation, '@@', -2) === 0) {
$todo[$message] = $translation;
} else {
$todo[$message] = '@@' . $translation . '@@';
diff --git a/framework/grid/CheckboxColumn.php b/framework/grid/CheckboxColumn.php
index ddb30dbf1c..531710aa0f 100644
--- a/framework/grid/CheckboxColumn.php
+++ b/framework/grid/CheckboxColumn.php
@@ -63,7 +63,7 @@ class CheckboxColumn extends Column
if (empty($this->name)) {
throw new InvalidConfigException('The "name" property must be set.');
}
- if (substr($this->name, -2) !== '[]') {
+ if (substr_compare($this->name, '[]', -2)) {
$this->name .= '[]';
}
}
diff --git a/framework/helpers/BaseHtml.php b/framework/helpers/BaseHtml.php
index 0e3dc82eff..204ab041eb 100644
--- a/framework/helpers/BaseHtml.php
+++ b/framework/helpers/BaseHtml.php
@@ -803,7 +803,7 @@ class BaseHtml
$options['name'] = $name;
if (isset($options['unselect'])) {
// add a hidden field so that if the list box has no option being selected, it still submits a value
- if (substr($name, -2) === '[]') {
+ if (substr_compare($name, '[]', -2) === 0) {
$name = substr($name, 0, -2);
}
$hidden = static::hiddenInput($name, $options['unselect']);
diff --git a/framework/web/UrlManager.php b/framework/web/UrlManager.php
index 3aeb23fba1..4d484696ba 100644
--- a/framework/web/UrlManager.php
+++ b/framework/web/UrlManager.php
@@ -238,7 +238,7 @@ class UrlManager extends Component
$suffix = (string) $this->suffix;
if ($suffix !== '' && $pathInfo !== '') {
$n = strlen($this->suffix);
- if (substr($pathInfo, -$n) === $this->suffix) {
+ if (substr_compare($pathInfo, $this->suffix, -$n) === 0) {
$pathInfo = substr($pathInfo, 0, -$n);
if ($pathInfo === '') {
// suffix alone is not allowed
diff --git a/framework/web/UrlRule.php b/framework/web/UrlRule.php
index fdb0ddf3e7..18d5d32484 100644
--- a/framework/web/UrlRule.php
+++ b/framework/web/UrlRule.php
@@ -215,7 +215,7 @@ class UrlRule extends Object implements UrlRuleInterface
$suffix = (string) ($this->suffix === null ? $manager->suffix : $this->suffix);
if ($suffix !== '' && $pathInfo !== '') {
$n = strlen($suffix);
- if (substr($pathInfo, -$n) === $suffix) {
+ if (substr_compare($pathInfo, $suffix, -$n) === 0) {
$pathInfo = substr($pathInfo, 0, -$n);
if ($pathInfo === '') {
// suffix alone is not allowed