You are here: beginner oop: class not alway working « All PHP « IT news, forums, messages
beginner oop: class not alway working

Posted by Osewoudt on 03/28/07 18:43

hello,

i am trying to learn oop, so i made a class that generates passwords.

there are several arrays and from some or each array there are elements
picked(at random) that
form the password.

the problem is: when i make an object the password shows.
but when i reload the page several times and/or changing the values that
form the
password (bv changing $test -> value = true, in , $test -> value -> false)
than nothing happens.

there is no password on the page and no error message, nothing.
the page is complely blank.

is there something wrong with the class?

thanks,


------------------------ code to show password -----------
// make an object;
$test = new WachtwoordGenerator();
// choose the amount of elements from each array;
$test -> kLetter = 8;
$test -> hLetter = 3;
$test -> cijfer = 2;
$test -> leesteken = 4;
// true means that the password contains only unique elements;
// false means that duplicates are allowed;
$test -> uniek = true;
// make the password;
$test -> maakWachtwoord();
// show the password
echo $test -> output();


------------------------- source code from the
class --------------------------------
class WachtwoordGenerator{

private $a;
private $b;
private $c;
private $d;

// amount of elements to choose;
private $aA;
private $aB;
private $aC;
private $aD;

private $wachtwoord;
// are duplicates allowed?
private $uniek;


function __construct() {
$this -> a =
array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p",
"q","r","s","t","u","v","w","x","y","z");
$this -> b =
array("A","B","C","D","D","E","F","G","H","I","J","K","L","M","N","O","P",
"Q","R","S","T","U","V","W","X","Y","Z");
$this -> c = array(0,1,2,3,4,5,6,7,8,9);
$this -> d = array("!","@","#","$","%","[","]");


$this -> wachtwoord = '';
}

function maakWachtwoord(){
// see if number is not larger than amount of elements in array;
$aantalA = sizeof($this -> a);
$aantalB = sizeof($this -> b);
$aantalC = sizeof($this -> c);
$aantalD = sizeof($this -> d);


if($this -> aA > $aantalA){
$this -> aA = $aantalA;
}

if($this -> aB > $aantalB){
$this -> aB = $aantalB;
}

if($this -> aC > $aantalC){
$this -> aC = $aantalC;
}

if($this -> aD > $aantalD){
$this -> aD = $aantalD;
}

$totaal = array($this -> a , $this -> b , $this -> c , $this ->
);
$aantal = array($this -> aA , $this -> aB, $this -> aC, $this ->
aD );

$wwRuw = array();

$aantalTotaal = sizeof($totaal);

for($y = 0; $y < $aantalTotaal; $y++){

for($x = 0; $x < $aantal[$y]; $x++){

$nummer = rand(0, sizeof($totaal[$y]) - 1 );
$teken = $totaal[$y][$nummer];

if($this -> uniek == true ) {

if(in_array($teken, $wwRuw)){

$x--;
continue;

}else{
$wwRuw[] = $teken;

}
} else {

$wwRuw[] = $teken;
}


}

}

//suffle the values;
shuffle($wwRuw);

// make a string/password
foreach($wwRuw as $k => $v){
$this -> wachtwoord .= $v;
}



}

function __set($p_sName, $p_nAmount) {
switch ($p_sName) {
case "kLetter" :
$this -> aA = $p_nAmount;
break;
case "hLetter" :
$this -> aB = $p_nAmount;
break;
case "cijfer" :
$this -> aC = $p_nAmount;
break;
case "leesteken" :
$this -> aD = $p_nAmount;
break;
case "uniek" :
$this -> uniek = $p_nAmount;
break;
}
}

function output(){
return $this -> wachtwoord;
}


}

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация