Black Friday is here! Take advantage of this unique opportunity and get up to 80% extra knowledge for free! Read more here
bf extended_2022

Discussion: Array set as class member not accessible from internal class methods

Douglas Northwell:3/29/2018 1:21

Hey, everyone. I don't quite understand why the array I declared as a public class member is accessible from within the class' constructor but not from any other method within the class. The program I'm making involves storing Album objects (generated black squares) within an albumContainer object.

Here is the albumContainer class:


Here is the album class:


Here is the main page where I instantiate the albumContainer object and call the render method:


Every time I run the code I get the following message:

Fatal error: Uncaught Error: Using $this when not in object context in C:\xampp\htdocs\Web Development\char­\sub­pages\classes\al­bumContainer.php:26 Stack trace: #0 C:\xampp\htdocs\Web Development\char­\sub­pages\home.php(11): albumContainer::ren­der() #1 C:\xampp\htdocs\Web Development\char­\in­dex.php(42): include('C:\\xam­pp\\htdocs...') #2 {main} thrown in C:\xampp\htdocs\Web Development\char­\sub­pages\classes\al­bumContainer.php on line 26

3/29/2018 1:21
Douglas Northwell:3/29/2018 1:55

I solved the issue. Turns out I was calling the method statically using the :: operator rather than the -> operator.

Up Reply
3/29/2018 1:55
To maintain the quality of discussion, we only allow registered members to comment. Sign in. If you're new, Sign up, it's free.

2 messages from 2 displayed.