Solved

step through lines of code

Posted on 2013-12-13
6
281 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
Independent Software Vendors: 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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

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.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

707 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