Calling member function from other member function in PHP? Calling member function from other member function in PHP? php php

Calling member function from other member function in PHP?


$this->push_back will call the method as part of the CURRENT object.

self::push_back calls the method as a static, which means you can't use $this within push_back.

push_back() by itself will attempt to call a push-back function from the global scope, not the push_back in your object. It is not an "object call", it's just a plain-jane function call, just as calling printf or is_readable() within an object calls the usual core PHP functions.


I cant seem to access it just by doing push_back(new SomeClass($file, $dtype)) like I would have expected.

This way you call push_back() as a function. There is no way around $this (for object methods) or self::/static:: (for class methods), because it would result into ambiguity

Just remember: PHP is not Java ;)


You can access like this

public static function abc($process_id){return 1;}public static function xyz(){$myflag=self::abc();return $myflag;}output : 1