I am a little confused by the situation shown in this code ...
class DirEnt { public function PopulateDirectory($path) { while ($file = readdir($folder)) { is_dir($file) ? $dtype = DType::Folder : $dtype = Dtype::File; $this->push_back(new SomeClass($file, $dtype)); } }
Why do I need to use $this->push_back(new SomeClass($file, $dtype)) or self::push_back(new SomeClass($file, $dtype)) to call the push_back member function? It seems I cannot access it just by doing push_back(new SomeClass($file, $dtype)) as I expected. I read When to use self over $ this? but he didn’t answer why I need one of them at all (or if I do at all, maybe I ruined something else up).
Why is this specification needed when members are non-stationary and are in the same class? Should all member functions be visible and known from other member functions in the same class?
PS: it works fine with $this-> and self:: , but talks about unknown functions when none of them are present in the push_back call.
methods php
John Humphreys - w00te
source share