Solved

explain call stack

Posted on 2014-03-23
5
486 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 110

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 35

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 35

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Ahax pagination 9 48
JQuery Search Filter 2 70
Converting PHP triple des decrypt to c# 9 70
using json to get the form data to assign it into php variables 33 22
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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.
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 …

749 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