?
Solved

explain call stack

Posted on 2014-03-23
5
Medium Priority
?
492 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 800 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 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 400 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 800 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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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 and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

765 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