也有一些是像coding standard
为Magento的1,称为ECG
其中有大量的事情,应避免或不应该使用的方法。
让我们尝试创建一个列表,其中包含在代码中引发“错误”或“警告”的所有情况。
您将在下面找到所有可能的警告的列表。我会定期更新此帖子,并链接到给定和推荐的答案。
注意:请尽量避免重复的答案;)
下载:https : //github.com/magento-ecg/coding-standard
心电图闻
班级
Mysql4类已过时。
在Magento中不建议使用直接对象实例化(类%s)。
protected $disallowedClassPrefixes = array(
'Mage_',
'Enterprise_',
);
...
的PHP
不鼓励使用goto。
...
未指定“'。$ exceptionClassName。'”类的命名空间。
...
检测到私人班级成员。
...
检测到私人班级成员。
...
性能
不必要地加载了Magento数据集合。请改用getSize()方法。
对于大型数据集,fetchAll()可能会使内存效率低下。
...
getFirstItem()不会将集合加载的结果限制为一个项目。
- GetFirstItem- https: //magento.stackexchange.com/a/179309/46249
在循环中检测到数组大小计算功能%s
在循环中检测到模型LSD方法%s
在循环中检测到数据加载%s方法
protected $countFunctions = array(
'sizeof',
'count'
);
protected $modelLsdMethods = array(
'load',
'save',
'delete'
);
- 加载
- ...
安全
%s类中缺少%s()ACL方法。
const PARENT_CLASS_NAME = 'Mage_Adminhtml_Controller_Action';
const REQUIRED_ACL_METHOD_NAME = '_isAllowed';
...
public $forbiddenFunctions = array(
'^is_dir' => null,
'^is_file$' => null,
'^pathinfo$' => null,
);
...
public $forbiddenFunctions = array(
'^assert$' => null,
'^bind_textdomain_codeset$' => null,
'^bindtextdomain$' => null,
'^bz.*$' => null,
'^call_user_func$' => null,
'^call_user_func_array$' => null,
'^chdir$' => null,
'^chgrp$' => null,
'^chmod$' => null,
'^chown$' => null,
'^chroot$' => null,
'^com_load_typelib$' => null,
'^copy$' => null,
'^create_function$' => null,
'^curl_.*$' => null,
'^cyrus_connect$' => null,
'^dba_.*$' => null,
'^dbase_.*$' => null,
'^dbx_.*$' => null,
'^dcgettext$' => null,
'^dcngettext$' => null,
'^dgettext$' => null,
'^dio_.*$' => null,
'^dirname$' => null,
'^dngettext$' => null,
'^domxml_.*$' => null,
'^exec$' => null,
'^fbsql_.*$' => null,
'^fdf_add_doc_javascript$' => null,
'^fdf_open$' => null,
'^fopen$' => null,
'^fsockopen$' => null,
'^ftp_.*$' => null,
'^fwrite$' => null,
'^gettext$' => null,
'^gz.*$' => null,
'^header$' => null,
'^highlight_file$' => null,
'^ibase_.*$' => null,
'^id3_set_tag$' => null,
'^ifx_.*$' => null,
'^image.*$' => null,
'^imap_.*$' => null,
'^ingres_.*$' => null,
'^ircg_.*$' => null,
'^ldap_.*$' => null,
'^link$' => null,
'^mail$' => null,
'^mb_send_mail$' => null,
'^mkdir$' => null,
'^move_uploaded_file$' => null,
'^msession_.*$' => null,
'^msg_send$' => null,
'^msql$' => null,
'^msql_.*$' => null,
'^mssql_.*$' => null,
'^mysql_.*$' => null,
'^odbc_.*$' => null,
'^opendir$' => null,
'^openlog$' => null,
'^ora_.*$' => null,
'^ovrimos_.*$' => null,
'^parse_ini_file$' => null,
'^parse_str$' => null,
'^parse_url$' => null,
'^parsekit_compile_string$' => null,
'^passthru$' => null,
'^pcntl_.*$' => null,
'^posix_.*$' => null,
'^pfpro_.*$' => null,
'^pfsockopen$' => null,
'^pg_.*$' => null,
'^php_check_syntax$' => null,
'^popen$' => null,
'^print_r$' => null,
'^printf$' => null,
'^proc_open$' => null,
'^putenv$' => null,
'^readfile$' => null,
'^readgzfile$' => null,
'^readline$' => null,
'^readlink$' => null,
'^register_shutdown_function$' => null,
'^register_tick_function$' => null,
'^rename$' => null,
'^rmdir$' => null,
'^scandir$' => null,
'^session_.*$' => null,
'^set_include_path$' => null,
'^set_ini$' => null,
'^set_time_limit$' => null,
'^setcookie$' => null,
'^setlocale$' => null,
'^setrawcookie$' => null,
'^shell_exec$' => null,
'^sleep$' => null,
'^socket_.*$' => null,
'^stream_.*$' => null,
'^sybase_.*$' => null,
'^symlink$' => null,
'^syslog$' => null,
'^system$' => null,
'^touch$' => null,
'^trigger_error$' => null,
'^unlink$' => null,
'^vprintf$' => null,
'^mysqli.*$' => null,
'^oci_connect$' => null,
'^oci_pconnect$' => null,
'^quotemeta$' => null,
'^sqlite_popen$' => null,
'^time_nanosleep$' => null,
'^base64_decode$' => null,
'^base_convert$' => null,
'^basename$' => null,
'^chr$' => null,
'^convert_cyr_string$' => null,
'^dba_nextkey$' => null,
'^dns_get_record$' => null,
'^extract$' => null,
'^fdf_.*$' => null,
'^fget.*$' => null,
'^fread$' => null,
'^fflush$' => null,
'^get_browser$' => null,
'^get_headers$' => null,
'^get_meta_tags$' => null,
'^getallheaders$' => null,
'^getenv$' => null,
'^getopt$' => null,
'^headers_list$' => null,
'^hebrev$' => null,
'^hebrevc$' => null,
'^highlight_string$' => null,
'^html_entity_decode$' => null,
'^ibase_blob_import$' => null,
'^id3_get_tag$' => null,
'^import_request_variables$' => null,
'^ircg_nickname_unescape$' => null,
'^ldap_get_values$' => null,
'^mb_decode_mimeheader$' => null,
'^mb_parse_str$' => null,
'^mcrypt_decrypt$' => null,
'^mdecrypt_generic$' => null,
'^msg_receive$' => null,
'^ngettext$' => null,
'^ob_get_contents$' => null,
'^ob_get_flush$' => null,
'^rawurldecode$' => null,
'^shm_get_var$' => null,
'^stripcslashes$' => null,
'^stripslashes$' => null,
'^token_get_all$' => null,
'^unpack$' => null,
'^convert_uudecode$' => null,
'^iconv_mime_decode$' => null,
'^iconv_mime_decode_headers$' => null,
'^iconv_mime_encode$' => null,
'^iconv_set_encoding$' => null,
'^php_strip_whitespace$' => null,
'^addcslashes$' => null,
'^addslashes$' => null,
'^escapeshellarg$' => null,
'^escapeshellcmd$' => null,
'^gettype$' => null,
'^var_dump$' => null,
'^tempnam$' => null,
'^realpath$' => null,
'^linkinfo$' => null,
'^lstat$' => null,
'^stat$' => null,
'^lchgrp$' => null,
'^lchown$' => null,
'^show_source$' => null,
'^is_executable$' => null,
'^is_link$' => null,
'^is_readable$' => null,
'^is_writable$' => null,
'^is_writeable$' => null,
'^is_uploaded_file$' => null,
'^glob$' => null,
'^ssh2_.*$' => null,
'^delete$' => null,
'^file.*$' => null,
);
- ...
- curl_: - https://magento.stackexchange.com/a/178642/46249
- file_exists- https: //magento.stackexchange.com/a/178641/46249
- ...
检测到“%s”语句。不鼓励进行文件操作。
...语句不是函数,不需要括号。
...禁止传递网址。
...禁止串联。
...里面的变量是不安全的。
public $urlPattern = '#(https?|ftp)://.*#i';
...
反引号字符串常量的用法不正确。反引号应始终位于字符串内。
不鼓励使用%s语言构造。
return array(
T_EXIT,
T_ECHO,
T_PRINT,
T_BACKTICK
);
...
直接检测到%s Superglobal。
public $superGlobalErrors = array(
'$GLOBALS',
'$_GET',
'$_POST',
'$_SESSION',
'$_REQUEST',
'$_ENV'
);
public $superGlobalWarning = array(
'$_FILES',
'$_COOKIE',
'$_SERVER',
);
SQL
检测到可能的原始SQL语句%s
public $statements = array(
'SELECT',
'UPDATE',
'INSERT',
'CREATE',
'DELETE',
'ALTER',
'DROP'
);
public $queryFunctions = array(
'query',
'raw_query'
);
...
检测到可能的慢速SQL语句%s
检测到可能的慢速SQL方法%s
public $adapterMethods = array(
'group',
'having',
'distinct',
'addLikeEscape',
'escapeLikeValue',
'union',
'orHaving',
);
public $rawStatements = array(
'GROUP BY',
'HAVING',
'DISTINCT',
'LIKE',
'UNION',
);
...
弦乐
%s中可能的可执行正则表达式。确保模式不包含“ e”修饰符
public $functions = array(
'preg_replace',
);
...
使用+运算符连接检测到的两个字符串
...
相同的运算符===不用于测试%s函数的返回值
public $functions = array(
'strpos',
'stripos',
);
- http://php.net/manual/en/function.strpos.php#refsect1-function.strpos-examples
- http://php.net/manual/zh/function.stripos.php#refsect1-function.stripos-examples
最佳实践的相关问题和答案