Backend Development

Error with class array

Submitted by bVnDBsapg, , Thread ID: 97384

Thread Closed
bVnDBsapg
Novice
Level:
0
Reputation:
2
Posts:
21
Likes:
0
Credits:
0
01-08-2018, 11:50 PM
#1
A while ago I was trying to learn PHP OOP by using classes to make a simple forum system. I have a function that will return an array of Post objects. The problem I'm having is I tried to loop over them and call a function, but for some reason PHP is treating them like a number. I have it check if the object is an instanceof Post yet it doesn't work.

Heres a snippet of my code:

PHP Code:
$posts Database::LoadPosts(isset($_GET['page']) ? intval($_GET['page']) : 1);

  for(
$i=0$i sizeof($posts); $i++){
    
$post $posts[$i];
    if(
$post instanceof Post) {
      echo 
$post->GetHTML();
    }
  } 

Users browsing this thread: 1 Guest(s)