Solved

step through lines of code

Posted on 2013-12-13
6
275 Views
Last Modified: 2013-12-16
from
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28314416.html

<?php
class Couch extends HouseholdObject{
  function who(){
	echo get_class()."\n";
  }
}

class Refrigerator extends HouseholdObject{
  Public static function createself(){
    return new self();
  }
  function who(){
	echo get_class()."\n";
  }
}

class BigRefrigerator extends Refrigerator{
  function who(){
	echo get_class()."\n";
  }
}

Abstract class HouseholdObject{
  Public static function createstatic(){
    return new static();
  }

  // The existence of this would create a Fatal PHP error
  // As it is inside an Abstract object - which has no "self" capability.
  //  Public static function createself(){
  //    return new self();
  //  }

  function who(){
	echo get_class()."\n";
  }
}

$couchstatic = Couch::createstatic();
$bigfridgestatic = BigRefrigerator::createstatic();
$bigfridgeself = BigRefrigerator::createself();

$couchstatic->who();
$bigfridgestatic->who();
$bigfridgeself->who();

?>

Open in new window


This will not work in my php ide with only php 5.2 (I can not change) which debugs by stepping through lines one at a time

Could you tell me
1. why this works
2. which line is run, first, second, third, fourth...
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
6 Comments
 
LVL 18

Expert Comment

by:Mark Gilbert
ID: 39718245
From reading the language in your question, I wonder whether this is an assignment that you need assistance on. Is this an assignment? The code of conduct at Experts Exchange encourages discussion and learning but does not providing "the solution" but helping you find it.

If you want to step through code, especially PHP code, you will need Zend Server, and the Zend IDE.

PHP is a procedural language, meaning it will execute in the order it's written, and included. It can jump around files and execute pieces of code from those files, and it always runs in order. From the example you provide, you're defining classes, with methods, and those methods are then instantiated at the end of the file. Using the information I've provided, I hope you're now able to work out which pieces of code match the questions.

I recommend reading up on OOP or object oriented programming in PHP, there are many free resources out there that a google or EE search should present for you.

Hope this helps.
0
 
LVL 14

Accepted Solution

by:
ThG earned 250 total points
ID: 39718756
the execution result is:

Couch
BigRefrigerator
Refrigerator
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39720322
PHP 5.2 is not supported any more, not even for security fixes.  PHP 5.3 has been current for years, and now even 5.3 is in the glide path!  PHP 5.4+ is probably closer to "current."

What's keeping you from changing the IDE?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:rgb192
ID: 39720550
No other ide steps through lines of code.
0
 
LVL 110

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
ID: 39720566
Outside the box... Add breakpoints by adding echo and var_dump() statements, just like you did in the code snippet lines 43-45.  This is what I do and it works well when you get used to it after a couple of exercises.
0
 

Author Closing Comment

by:rgb192
ID: 39722325
Ok vardump and the output
Thanks both.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
TCPDF - Create PDF from Form Values and Link to PDF Download 7 46
Undefined variable problem 5 32
How to use session variables in php? 22 42
deprecated mysql extensions 1 22
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
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…

740 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