ColdFusion 对象是按引用传递还是按值传递?
ColdFusion 对象(即通过 cfobject 调用的 CFC)通常是按引用传递还是按值传递(复制到内存中)? 是否可以强制 ColdFusion 以任一方式传递对象?
Are ColdFusion objects (i.e. CFCs invoked via cfobject) normally passed by reference or by value (copied in memory)? And is it possible to force ColdFusion to pass an object in either manner?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
ColdFusion 对象通过引用传递。 确实没有一种方法可以按值传递对象,但您可以使用duplicate() 函数创建一个副本。
ColdFusion objects are passed by reference. There's not really a way to pass an object by value, but you can create a copy using the duplicate() function.
好吧,请记住,使用重复() 在 MX 7 中不起作用 用于复制某些内容,例如 CFC 和 COM、CORBA 和 Java 对象。 不过,您可以在 CF 8 中复制 CFC。
Well, keep in mind that using duplicate() doesn't work in MX 7 for copying certain things, like CFCs and COM, CORBA, and Java objects. You can copy a CFC in CF 8, though.
结构和 CFC 等复杂对象是通过引用传递的,但如果将数组传递给 UDF,则它是通过值传递的。 这使得不可能编写像内置数组函数那样改变数组的用户定义函数。 如果确实需要通过引用传递数组,可以将其包装在结构体中,然后它将通过引用传递。
Complex objects such as structs and CFCs are passed by reference, but if you pass an array to a UDF it is passed by value. This makes it impossible to write a user defined function that mutates an array like the built-in array functions do. If you really need to pass an array by reference, you can wrap it in a struct, and then it will be passed by reference.
FWIW,数组也在 Railo CFML 引擎中通过引用传递,正如许多开发人员认为的那样。 Railo 3.1 预计还将提供管理设置,允许您选择默认行为,以实现与 Adobe CF 的可选兼容性。
FWIW, arrays are also passed by reference in the Railo CFML engine, as many developers believe they should. Railo 3.1 is also expected to offer an administrative setting to allow you to choose the default behavior, for optional compatibility with Adobe CF.