PHP:在html文件中使用javascript时,我可以在全局范围内分配var mythis = this。 PHP中有类似的方法吗?

问题描述 投票:0回答:1

[在html文件中使用javascript时,我可以在全局范围内分配var mythis=this。 PHP中有类似的方法吗?

<html><head>
<script> var mythis= this;</script>
</head><body></body></html>

这在php中也是可能的吗?

<?php
$mythis = ....????

// or in a function or class?

function a() { $t = ....????; }


?>
php class this global parent
1个回答
0
投票

$ this在PHP中是一个伪变量,当在对象的上下文中调用方法时,该引用是对调用对象的引用。例如:

<?php
class A{
    private $a = 1;

    public function getA(){
        return $this->a;
    }
}?>
© www.soinside.com 2019 - 2024. All rights reserved.