Non-Static Method ..... Should Not Be Called Statically

Non-static method ..... should not be called statically

That means it should be called like:

$timer = (new VTimer)->get($options['magic']);

The difference between static and non-static is that the first one doesn't need instantiation so you can call the classname then append :: to it and call the method immediately.
Like so:

ClassName::method();

and if the method is not static you need to initialize it like so:

$var = new ClassName();
$var->method();

However, in PHP >=5.4 you can use this syntax instead as a shorthand:

(new ClassName)->method();

Non-static method AJAXChatFileSystem::getFileContents() should not be called statically

Calling a non-static method statically in PHP is deprecated behaviour since version 7.0 and raises an E_DEPRECATED warning. This means that support for this behavour works, but may (and probably will) be removed in a future version.

This behaviour raised an E_STRICT warning in PHP versions 5.*.

Changing your own AJAXChatTemplate::getContent() method to static does not work because it uses $this which only makes sense in the context of an instance of a class. Therefore it triggers a fatal error in a static context.

You are using the AJAX-Chat library—you haven't stated what version you are using but there is an issue that discusses the error you encounterd.

In line with this reported issue, a commit to recent versions of this library were made to change this a static behaviour.


To resolve your issue, you have two choices:

Continue to use the version of AJAX-Chat that you have currently installed

Just use the AJAXChatFileSystem::getFileContents() non-statically. Create an instance of the class and use that by modifying your getContent() method like so:

function getContent()
{
if (!$this->_content) {
$ajaxChatFileSystem = new AJAXChatFileSystem();
$this->_content = $ajaxChatFileSystem->getFileContents($this->_templateFile);
}

return $this->_content;
}

Upgrade to the latest version of this library and use the static method

There does not appear to be a changelog, so you should test your code wherever you use AJAX-Chat to ensure there are no breaking changes.


Technically, you have a third choice: since this is an E_DEPRECATED warning—implying that the functionality is flagged for removal at a future date—you can safely ignore this warning, for now.

E_DEPRECATED warnings (as with all notices, warnings and errors) should be disabled from display to the user in production code.

However, I do not recommend this because your logs will be full of E_DEPRECATED warnings. Moreover, as already mentioned, future versions of PHP may remove support for calling non-static methods statically.

Hope this helps :)

Deprecated: Non-static method AriKernel::init() should not be called statically in

We don't know your class' code, however rule is simple, most of contemporary IDEs will allow you to choose only methods of proper types while typing:

<?php

class MyClass
{
public static function myStaticMethod()
{
echo 'This is static method';
}

public function myNONStaticMethod()
{
echo 'This is NON-static method';
}
}

// call of static method
MyClass::myStaticMethod();

// call of NON static method
$object = new MyClass();
$object->myNONStaticMethod();

Error message Strict standards: Non-static method should not be called statically in php

Your methods are missing the static keyword. Change

function getInstanceByName($name=''){

to

public static function getInstanceByName($name=''){

if you want to call them statically.

Note that static methods (and Singletons) are death to testability.

Also note that you are doing way too much work in the constructor, especially all that querying shouldn't be in there. All your constructor is supposed to do is set the object into a valid state. If you have to have data from outside the class to do that consider injecting it instead of pulling it. Also note that constructors cannot return anything. They will always return void so all these return false statements do nothing but end the construction.

ErrorException Non-static method should not be called statically - When Try to Fetch Data from Two Different Table

Please add get(), first() to the end of expression. That may do the trick.

$usertype = TeacherProfile::with('usertype.teacher')->get();


Related Topics



Leave a reply



Submit