Solved

explain call stack

Posted on 2014-03-23
5
476 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 74

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 108

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

746 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now