Home>

Hello everyone, is a question in the class relevant today.

First, I will show you the code.

<?php
// Your code here!
class Hoge {
    private $name;
    public function __construct($name) {
        $this->name = $name;
    }
    public static function getName() {
        return $this->name;
    }
}
$arr = [
    'Apple',
    "Koala",
    'rap',
    ];
$hoge = new Hoge('apple');
$nam = $hoge::getName();
function getFruit($arr, $name) {
    foreach ($arr as $name) {
        if ($name == $name) {
         echo'matches';
        }
    }
}
$result = getFruit($arr, $nam);


What I want to do is throw in the requestValue [name]The transition destinationHoge class property [name]
I would like to compare it with and process it when it matches.
However, with the current source, the following error occurred and the value could not be obtained.

PHP Fatal error: Uncaught Error: Using $this when not in object context Hoge.php line 7


Regarding access rights, we have the following recognition.
public...accessible from anywhere
protected.....accessible only from the class and the class that inherits the class
private.....accessible only from within the class that defines the member

Note that the getName method is static, also for the practice of static invocation.
It is statically made.

Please lend us the power of experts.

php