Help understanding/debugging the following script:
| From: | Martin Bach Nielsen | Date: | Thu, 21 Sep 2006 17:26:28 +0000 |
| Subject: | Help understanding/debugging the following script: | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-242033@lists.php.net to get a copy of this message | ||
Hi all.
If you look at the code below, the return() does not produce any output.
No errors were displayed on screen before I added 'error_reporting(E_ALL);'.
(Error message: Notice: Undefined variable: this in /oop/test1/index.php on
line 35, commented on below)
Trying to echo/print ordinary text or variables works fine.
I have some experience coding PHP scripts, but are new on how-to use/write
OOP scripts. (Sample found at: http://www.purephotoshop.com/view.php?id=71)
Here's the Code:
<?php
error_reporting(E_ALL);
class Bike
{
var $num_speeds, $speed;
var $rotation;
var $running = FALSE; // You can set default values for properties,
these values must be constant
// Change speed method
function change_speed( $increment = TRUE )
{
// ...
}
// Pedal and brake methods
function pedal()
{
// ...
}
function brake()
{
// ...
}
// Turn method
function turn( $angle )
{
// ...
}
}
// Inside the change_speed() method
if( !$this->running ) // This is line 35
{
return;
}
if( $increment && $this->speed != $this->num_speeds )
{
$this->speed++;
return;
}
if( $this->speed != 1 )
{
$this->speed--;
}
?>
I will be thankful for any help/hints that leads to a solution. If anymore
info are needed, please let me know.
Regards,
Martin