PHP
<?php
/**
* @author Patrick rennings
* @copyright 2010
*/
class Tafel {
protected $iCount;
protected static $iMaxOutPut;
protected $MathOutPut;
public function __construct ( $Count, $MaxOutPut = NULL)
{
if ( !is_int ( $Count ) OR empty ( $Count ) )
{
$this->iCount = 1;
}
else
{
$this->iCount = $Count;
}
if ( !is_int ( $MaxOutPut ) OR empty ( $MaxOutPut ) AND empty ( self::$iMaxOutPut ) )
{
self::$iMaxOutPut = 10;
}
else
{
self::$iMaxOutPut = $MaxOutPut;
}
$this->Math( $this->iCount, self::$iMaxOutPut );
}
private function Math ( $CalcNum, $MaxOutPut )
{
$sArrayMath = array ( );
for ( $iMath = 1; $iMath <= $MaxOutPut; $iMath++ )
{
$sArrayMath[] = $iMath . ' x ' . $CalcNum . ' = ' . $iMath * $CalcNum;
}
$this->MathOutPut = $sArrayMath;
}
public function ResultMath ( )
{
return $this->MathOutPut;
}
}
$Math = new Tafel (4,20);
foreach ( $Math->ResultMath() AS $Calculation )
{
echo $Calculation . ' <br /> ';
}
$Math2 = new Tafel (5);
foreach ( $Math2->ResultMath() AS $Calculation )
{
echo $Calculation . ' <br /> ';
}
?>
Toon Meer
Alles werkt, behalve de static variable, als ik de waarde = NULL meegeef aan $MaxOutPut wordt hij automatisch 10, maar als ik hem niet meegeef gaat hij mekkere dat er niks in staat,
Hoe kan ik er een check inbouwen dat wanneer de static variable is gevuld dat hij die gewoon pakt wanneer er geen nieuwe gedefinieerd is?
UPDATE:
zo werkt hij naar mijn zin
Comments?
PHP
<?php
/**
* @author Patrick rennings
* @copyright 2010
*/
class Tafel {
protected $iCount;
protected static $iMaxOutPut;
protected $MathOutPut;
public function __construct ( $Count, $MaxOutPut = NULL)
{
if ( !is_int ( $Count ) OR empty ( $Count ) )
{
$this->iCount = 1;
}
else
{
$this->iCount = $Count;
}
if ( ( !is_int ( $MaxOutPut ) OR empty ( $MaxOutPut ) ) AND empty ( self::$iMaxOutPut ) )
{
self::$iMaxOutPut = 10;
}
elseif ( empty ( self::$iMaxOutPut ) OR ! empty ( $MaxOutPut ) )
{
self::$iMaxOutPut = $MaxOutPut;
}
$this->Math( $this->iCount, self::$iMaxOutPut );
}
private function Math ( $CalcNum, $MaxOutPut )
{
$sArrayMath = array ( );
for ( $iMath = 1; $iMath <= $MaxOutPut; $iMath++ )
{
$sArrayMath[] = $iMath . ' x ' . $CalcNum . ' = ' . $iMath * $CalcNum;
}
$this->MathOutPut = $sArrayMath;
}
public function ResultMath ( )
{
return $this->MathOutPut;
}
}
$Math = new Tafel (4,20);
foreach ( $Math->ResultMath() AS $Calculation )
{
echo $Calculation . ' <br /> ';
}
$Math2 = new Tafel (5);
foreach ( $Math2->ResultMath() AS $Calculation )
{
echo $Calculation . ' <br /> ';
}
?>
Toon Meer