Solved

step through lines of code

Posted on 2013-12-13
6
268 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: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 109

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
ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

 

Author Comment

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

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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 …

803 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