How to invoke a method statically?

<?php
class Popular
{
    public static function getVideo()
    {
        return $this->parsing();
    }
}

class Video 
    extends Popular
{
    public static function parsing()
    {
        return 'trololo';
    }

    public static function block()
    {
        return parent::getVideo();
    }
}

echo Video::block();

I should definitely call the class this way:

Video::block();

and not initialize it

$video = new Video();
echo $video->block()

Not this!

Video::block(); // Only this way <<

But: Fatal error: Using $this when not in object context in myFile.php on line 6

How to call function "parsing" from the "Popular" Class?

Soooooooory for bad english

Answers


As your using a static method, you cant use $thiskeyword as that can only be used within objects, not classes.

When you use the new keyword, your creating and object from a class, if you have not used the new Keyword then $this would not be available as its not an Object

For your code to work, being static you would have to use the static keyowrd along with Scope Resolution Operator (::) as your method is within a parent class and its its not bounded, Use the static keyword to call the parent static method.

Example:

class Popular
{
    public static function getVideo()
    {
        return static::parsing(); //Here
    }
}

Need Your Help

glibc detected realloc(): invalid pointer

c pointers memory-management

Im constantly getting this when I build on Qtcreator.

Changing Passenger Default Error Page for Nginx

ruby-on-rails nginx passenger

Currently if there's a problem launching a Rails app on our server, users are taken to a Passenger error page with an error like "Ruby (Rack) application could not be started".