PHP 操作顺序
我想知道 PHP 如何执行这个。操作顺序
addslashes(strip_tags($record['value']));
首先调用addslashes 还是先调用strip_tags?
换句话说,它是从内向外执行还是从外向内执行?
I wanted to know how PHP would execute this. Order of operations
addslashes(strip_tags($record['value']));
Is addslashes called first or strip_tags?
In other words, does it execute from the inside out or from the outside in?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
从内到外。
PHP 中传递给函数的东西称为“表达式”。当您将表达式作为参数传递时,您真正传递的是该表达式的值。为此,在传入表达式之前对其进行求值。
有关表达式的更多信息,请参见 php 手册。
From the inside out.
The things passed into a function in PHP are called "expressions". When you pass an expression as a parameter, what you're really passing is the value of that expression. In order to do that, the expression is evaluated before it is passed in.
More about expressions from the php manual.
strip_tags 首先被调用。
这不仅是 PHP 的情况,也是所有其他编程语言的情况(不包括一些晦涩难懂的语言,它们可能具有某些独特的求值顺序)。
PS:这里有一些文档:PEDMAS。这也是编程语言中这种评估顺序的灵感来源。
strip_tags is called first.
and this is not just the case with PHP, it is the case with every other programming language (excluding some obscure esoteric language that may have some unique order of evaluation).
PS: Here is some documentation: PEDMAS. This is what inspired this kind of evaluation order in programming languages too.
如果您以逻辑方式思考,PHP 需要什么才能执行该函数?变量。因此,
strip_tags
需要先输入$record['value']
,然后才能执行该函数并从中剥离标签。该函数将返回一个值。现在,addslahes 也需要一个变量。它不能在函数上执行,它需要内部的函数返回一些东西来供它处理。因此它使用从
strip_tags
返回的值作为变量并执行。If you think about it in a logical way, what does PHP need in order to execute the function? The variable. So,
strip_tags
needs the$record['value']
to be inputted before it can execute the function and strip the tags from it. That function will return a value.Now,
addslahes
needs a variable too. It cannot execute on a function, it needs that function inside it to return something for it to process. So it uses that returned value fromstrip_tags
as its variable and executes upon that.addslashes
采用一个参数,在您的情况下,它是strip_tags($record['value'])
。当参数未解析时,无法调用
addslashes
。因此必须首先调用
strip_tags
。几乎所有流行的编程语言都是这种情况。我想知道你在知道这一点之前是如何度过的!addslashes
takes one argument, in your case it isstrip_tags($record['value'])
.addslashes
can't be called when it's argument isn't resolved.Therefore
strip_tags
must be called first. This is the case in nearly all popular programming languages out there. I wonder how you managed to get by before knowing this!