PHP Classes - how to access this properly

Ok, I’m here because I got utterly sick of stackoverflow downvotes. Let’s see how this goes.

Here’s the classes code I’m trying to understand. I hope this is clear enough.

class My_Looping_Class {

   public function __construct() {
        for($y=0;$y<=10;$y++) {

   private function do_loop() {
    //in this loop the value of $x in My_Var_Class gets incremented each loop but I'm not exactly 
    //sure how to call it.    

class My_Var_Class {

  public $x = 0;


class My_Looping_Class_Copy extends My_Looping_Class {

     function show_x() {
     //Show the $x in My_Var_Class each time it gets incremented.
     echo $x.'<br>';
     // Here I need to be able to read and echo the value of x in My_Var_Class each time it 
     //changes but again, I'm unsure of how to call it.

new My_Looping_Class_Copy();

How about telling us what the real problem is that you are trying to solve with this code.

Ok, you asked for it.

I have some old code that uses PHPCrawl.

Unfortunately, that library hasn’t been updated in years and the code quit working properly some time ago. So, I’m working on creating my own crawler from scratch. I’ve studied how his code works but parts of it leave me in the dark. His code has 2 classes of interest to me. The main class which you instantiate in your code, pass a url to it and it begins crawling, and another class which simply holds variables. As each website is downloaded, parsed, etc, the main class updates the class that holds the variables.

Here’s his example code: PHPCrawl webcrawler library for PHP - Example script

In his example, you instantiate PHPCrawler. Pass a url to it, set some other parameters then, run the $crawler->go function. This starts it crawling. As it finished crawling and parsing a site, the handleDocumentInfo($DocInfo) function is called so that you can get all the variables from the url you entered. It creates an array of url’s it finds and then starts crawling them and again, fires the handleDocumentInfo($DocInfo) after each one.

I created that example code because it would do the same thing essentially but without several thousand lines of code. In my example, I’d like the function show_x() to be called every time the $x var in My_Var_Class changes. And that’s what I don’t quite understand how to do.

Sponsor our Newsletter | Privacy Policy | Terms of Service