Solved

explain call stack

Posted on 2014-03-23
5
484 Views
Last Modified: 2014-03-23
<?php
class ShopProduct {
    public $title;
    public $producerMainName;
    public $producerFirstName;
    public $price;

    function __construct(   $title, $firstName,
                            $mainName, $price ) {
        $this->title             = $title;
        $this->producerFirstName = $firstName;
        $this->producerMainName  = $mainName;
        $this->price             = $price;
    }

    function getProducer() {
        return "{$this->producerFirstName}".
               " {$this->producerMainName}";
    }

    function getSummaryLine() {
        $base  = "{$this->title} ( {$this->producerMainName}, ";
        $base .= "{$this->producerFirstName} )";
        return $base;
    }
}

class CdProduct extends ShopProduct {
    public $playLength;

    function __construct(   $title, $firstName,
                            $mainName, $price, $playLength ) {
        parent::__construct(    $title, $firstName,
                                $mainName, $price );
        $this->playLength = $playLength;
    }

    function getPlayLength() {
        return $this->playLength;
    }

    function getSummaryLine() {
        $base  = "{$this->title} ( {$this->producerMainName}, ";
        $base .= "{$this->producerFirstName} )";
        $base .= ": playing time - {$this->playLength}";
        return $base;
    }
}

class BookProduct extends ShopProduct {
    public $numPages;

    function __construct(   $title, $firstName,
                            $mainName, $price, $numPages ) {
        parent::__construct(    $title, $firstName,
                                $mainName, $price );
        $this->numPages = $numPages;
    }

    function getNumberOfPages() {
        return $this->numPages;
    }

    function getSummaryLine() {
        $base  = "$this->title ( $this->producerMainName, ";
        $base .= "$this->producerFirstName )";
        $base .= ": page count - $this->numPages";
        return $base;
    }
}

$product1 = new CdProduct("cd1", "bob", "bobbleson", 4, 50 );
print $product1->getSummaryLine();
print "\n";

$product2 = new BookProduct("book1", "harry", "harrelson", 4, 30 );
print $product2->getSummaryLine();
print "\n";

?>

Open in new window


at this point of the call stack there are many lines, please explain
call stack
0
Comment
Question by:rgb192
5 Comments
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 200 total points
ID: 39949134
A call stack is simply the listing of functions that have been called up to a certain point. As your program runs, it will execute functions, and each of those functions may themselves call other functions. Every time a function is called, it is basically added to the top of a stack (like a stack of dinner plates). Once a function has finished executing, it is removed from the stack. Using a function call stack, you can quickly see the order of execution of your program (at that point in time).
0
 
LVL 109

Assisted Solution

by:Ray Paseur
Ray Paseur earned 100 total points
ID: 39949154
+1 for kaufmed's great explanation!  Another term you may encounter is "stack trace."
0
 
LVL 34

Accepted Solution

by:
gr8gonzo earned 200 total points
ID: 39949157
If you woke up in the morning and you wanted to drive to the store, you would have to do several things. Obviously, you would need to get in the car first. But to get into the car, you would need to find your car keys. To find the car keys, you'd have to get up out of bed. Your call stack for that might look like:

1. Drive to store (the current thing you're doing)
2. Get into the car
3. Find car keys
4. Get out of bed (the first thing you did)

In call stacks, you read from the bottom to the top. So in your screenshot, you have three lines, which basically tell me that on line 72 of listing.021.php, you have code that tries to create a new CdProduct.

Then, in your CdProduct constructor (on line 34 of that same listing.021.php file), you create a new ShopProduct.

The call stack is finally showing that you are currently looking at line 10 in that file, and you're in the ShopProduct constructor.
0
 
LVL 34

Expert Comment

by:gr8gonzo
ID: 39949160
Man, I type too slow.
0
 

Author Closing Comment

by:rgb192
ID: 39949358
dinner plates, stack trace
and best daily activities (current on top)


thanks
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question