PHP: When using javascript in a html file I could assign var mythis=this in the global scope. Is there a similiar way in PHP?

52
December 08, 2019, at 09:00 AM

When using javascript in a html file I could assign var mythis=this in the global scope. Is there a similiar way in PHP?

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

Is this possible in php,too?

<?php
$mythis = ....????
// or in a function or class?
function a() { $t = ....????; } // looking for global's $this

?>

Edit: Without using namespace. However they work.

Answer 1

$this in PHP is a pseudo variable, when methods are called in the context of an object, a reference to the calling object. For example:

<?php
class A{
    private $a = 1;
    public function getA(){
        return $this->a;
    }
}?>
READ ALSO
Is there a Phar available for Microsoft Graph?

Is there a Phar available for Microsoft Graph?

I am trying to work with Microsoft Graph APIs using PHP as per https://docsmicrosoft

48
Tests do not run after upgrading from 4.3 to 4.4

Tests do not run after upgrading from 4.3 to 4.4

A project in Symfony 43 has a functional test suite with 43 tests that all pass

50
how can i limit the returned items into my second object

how can i limit the returned items into my second object

suppose that i have an object Discussions contain many messagesthe question here that i want to return a list discussion with the last message

53
Variable column name php sql select statement [duplicate]

Variable column name php sql select statement [duplicate]

So I am trying to get a specific row and column, but I am having trouble with inserting the variable into the SQL statementThis is what I have right now:

23