简体   繁体   English

什么是PHP中函数字符串的正确语法样式

[英]What is a proper syntax style for function strings in php

I'm learning php, and i notice its an extreme rich language with string related functions. 我正在学习php,我注意到它是一种非常丰富的语言,具有与字符串相关的功能。 Something i've not seen in other languages is the code below, i know its basics. 下面的代码是我用其他语言所没有看到的,我知道它的基础。 But what i wonder what is the common syntax style, to use for this. 但是我不知道要使用什么通用语法样式。

I just used f_...... to declare a function that is already usable. 我只是用f _......声明了一个已经可用的函数。

And i used sf_...... to put a function into its string callable form. 而且我使用sf _......将函数放入其字符串可调用形式。

I also tend to use a_ for arrays etc. But i am wondered is there some kind of popular standard. 我也倾向于将a_用于数组等。但是我想知道是否存在某种流行的标准。 With popular i mean used often but doesnt need to be compliant to specific complex norms. 流行,我的意思是经常使用,但不需要遵循特定的复杂规范。 i would just like to achive that other coders find it easy to read. 我只是想让其他编码人员发现它易于阅读。

    function f_RedText($a){ return "<font size='+1' color='#ff0000'>$a</font>";}
    $sf_redtext = "f_RedText";
    echo $sf_redtext("Peter");

It doesn't exactly fit your question but is a more general approach to coding guidelines in PHP. 它并不完全适合您的问题,而是一种更通用的PHP编码指南方法。

Have a look at PSR-1 and PSR-2 看看PSR-1PSR-2

Edit 编辑

or Zend or PEAR or Nette (hat tip to @DanFromGermany for comment ;)) ZendPEARNette (向@DanFromGermany提示的技巧;)

You can use what you think, keeping mind the php documentation. 您可以使用您的想法,紧记php文档。 If you wrote function f_RedText($a) then its ok. 如果您编写了function f_RedText($a)则可以。 Developers use as they want to use. 开发人员可以按需使用。 There is nothing standard pattern that all good developers have to follow. 所有优秀的开发人员都没有遵循任何标准模式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM