Solved

step through lines of code

Posted on 2013-12-13
6
262 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
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…

932 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

12 Experts available now in Live!

Get 1:1 Help Now