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

Testing JavaScript Click Event with Sinon

javascript bdd mocha sinon chai

I am trying to produce some test to be able to better understand how to test DOM events with the combination of Mocha, Chai, Sinon and jQuery. I want to check that the alert function is correctly

Is it better to use JSF HTML or JSF Core namespaces with inputText when performing validation?

validation jsf jsf-2 namespaces

I need to perform simple form validation using JSF. Looking at different online examples I see two patterns:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.