前几天我在 php 中遇到了一些奇怪的东西,但这个问题比这更笼统。
我想知道的是,是否有可能有一个函数返回据我所知意味着返回值/函数在堆栈上并将结果传递给一个接受引用的函数?
以我有限的知识,我会说不,但这只是我的一种感觉,而且我学会了在编程时永远不要相信自己的感觉。
前几天我在 php 中遇到了一些奇怪的东西,但这个问题比这更笼统。
我想知道的是,是否有可能有一个函数返回据我所知意味着返回值/函数在堆栈上并将结果传递给一个接受引用的函数?
以我有限的知识,我会说不,但这只是我的一种感觉,而且我学会了在编程时永远不要相信自己的感觉。
I'm not too familiar with references in PHP, but you can do this in C/C++ and some cases in C#.
The thing is that you have to be careful. A value on the stack is only valid as long as the function whos stack frame it belongs to hasn't returned (ignoring stuff like the red zone). C and C++ expect you to be smart enough to not use a dangling reference like this.
Anyway, it doesn't matter in PHP because it's a high level language and hides details of allocation like that from you. Most likely, all your objects are allocated on the heap.