I'm new to OOP. Last week was momentous as I got my first class to
actually do something.
Might as well admit this right up front, I am by no means "sold" on
the way OOP php works.
That said, here's WHY I'm not very excited about jumping further in
the OOpool:
(This is pseudo-code, I HIGHLY doubt the error is a matter of syntax.)
index.php:
require_once(a.class.php)
require_once(b.class.php)
require_once(c.class.php)
$a = new class A()
......
moving on to code in class A:
$b = new class B() ... which contains a 'helper method' to return
values from within this class
$c = new class C() ... which contains a reference to one of class B's
helper methods.
Both Class B and Class C 'extend' Class A
Class C throws these messages regarding the line with a reference to
$B->helperMethod()
Notice: Undefined variable: (Name of Class 😎 in /path/to/Class/C.php
on line 10
Fatal error: Call to a member function helperMethod() on a non-object
in /path/to/Class/C.php on line 10
I thought the whole idea behind OOP was to write small, reusable code
that would 'play well with others' and pass info around so that a
change in one place could affect necessary changes in another object's
state. AND so that one object could 'ask' another for information by
way of a getMethod().
So why is it so blinking difficult to get one class "see" another,
much less access the data in another?
That asked, I guess the more relevant question is how does one code so
that the Helper Method in class B() is actually available to be called
in class C?
Thanks in advance for any guidance you can offer.