Get up to 80 % extra points for free! More info:

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

Activities
Avatar
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:

albumContainer­.php

Here is the album class:

album.php

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

home.php

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­ts4all.com\sub­pages\classes\al­bumContainer.php:26 Stack trace: #0 C:\xampp\htdocs\Web Development\char­ts4all.com\sub­pages\home.php(11): albumContainer::ren­der() #1 C:\xampp\htdocs\Web Development\char­ts4all.com\in­dex.php(42): include('C:\\xam­pp\\htdocs...') #2 {main} thrown in C:\xampp\htdocs\Web Development\char­ts4all.com\sub­pages\classes\al­bumContainer.php on line 26

 
Reply
3/29/2018 1:21
Avatar
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.