Solved

step through lines of code

Posted on 2013-12-13
6
259 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
6 Comments
 
LVL 18

Expert Comment

by:ingwa
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 108

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

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

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

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…
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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 …

708 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

15 Experts available now in Live!

Get 1:1 Help Now