【问题标题】:php object operator -> without instance?php 对象运算符-> 没有实例?
【发布时间】:2012-04-04 13:48:34
【问题描述】:

我在我实现的脚本中有以下代码,它确实可以正常工作,只是想了解一下:

   $variable1 = function1();  // function1 is a class method, it’s file included per require_once 
   $ variable1 -> function2(); // function2 is a class method, it’s file included per require_once

这里不是 -> 对象运算符吗? 但是 $variable1 中没有初始化实例保存。

帮助赞赏

【问题讨论】:

    标签: php object operator-keyword


    【解决方案1】:

    这只是意味着function1() 返回一个对象。

    因此您可以使用该对象及其功能。

    例子:

    class Test {
        function function2(){
            echo "Hi";
        }
    }
    
    function function1(){ return new Test; }
    
    
    //SO:
    
    $variable1 = function1();  
    $variable1->function2(); 
    

    【讨论】:

    • function1()->function2() // PHP 5.4
    猜你喜欢
    • 1970-01-01
    • 2020-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-18
    • 2020-05-31
    • 2021-10-24
    相关资源
    最近更新 更多