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

In the previous quiz, Online PHP Quiz, we tested our experience gained from the course.

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
Avatar
yokhama67
Member
Avatar
yokhama67:10/30/2024 6:35

The Free Fire Advance Server is a beta testing platform for Garena’s Free Fire game, where selected players can try new, unreleased features. Participants report bugs and provide feedback in exchange for in-game rewards like diamonds and exclusive items.This allows players to experience new content ahead of others, enhancing their game knowledge and status within the Free Fire community.

 
Up Reply
10/30/2024 6:35
To maintain the quality of discussion, we only allow registered members to comment. Sign in. If you're new, Sign up, it's free.

3 messages from 3 displayed.