Hallo,

Ik zit met een vreemd probleempje, ik krijg de volgende meldingen terwijl die bij zowat identieke functies (aan het begin van de class) niet voorkomen:

Notice: Undefined variable: thumb in portfolio.class.php on line 77
Notice: Undefined variable: image in portfolio.class.php on line 96
Notice: Undefined variable: description in portfolio.class.php on line 115

Het gekke is dat als ik binnen de while loop de variabele echo dan bestaat ie, maar zodra ik het return bestaat ie ineens niet meer.....

<?php

class portfolio{

/* setup for the thumbs and images, depending on the var $dir, for example: playground/thumbs or playground/gallery */

public function index($dir){

/* read directory and put the files in an array */
$x=0;

$handle = opendir('public/content/' . $dir);

/* walk through directory and put the filenames in an array */
while (false != ($file = readdir($handle))) {
if($file!="."&&$file!=".."){
$arrimages[$x]=$dir.$file;
$x++;
}
}

$numimages=$x;

closedir($handle);

/* if the given directory is empty it's propably under construction, else the array has to be ordered by alfabet */
if($numimages==0){
echo'Currently under construction.';
}else{
/* sort by alphabet */
sort($arrimages);reset($arrimages);
}

return $arrimages;
}

/* get the descriptions from the database, each description owns a timestamp referring to the filenames */

public function descriptions($value){

$y=0;

$connection=new shared();
$connection->connect();

$descriptions=new mysql($value);
$query=$descriptions->select('','');

while($myDescriptions=$descriptions->FetchArray($query)){
extract($myDescriptions);
$arrdescr['id'][$y]=$id;
$arrdescr['descr'][$y]=$description;
$y++;
}

return $arrdescr;
}

// if a page is requested to edit a project- or playgrounditem the following functions are used

public function getthumb($source, $timestamp){
$handle = opendir('public/content/' . $source . '/thumbs/');

/* walk through directory till a file, depending on the timestamp, is found. */

while (false != ($file = readdir($handle))) {
if($file=="thumb_".$timestamp.".png" || $file=="thumb_".$timestamp.".jpeg" || $file=="thumb_".$timestamp.".jpg" || $file=="thumb_".$timestamp.".gif" || $file=="thumb_".$timestamp.".swf"){

$thumb['file']=$source.'/thumbs/'.$file;
$thumb['edit']=$file;
$thumb['source']=$source;

}
}

closedir($handle);
return $thumb;
}

public function getimage($source, $timestamp){
$handle = opendir('public/content/' . $source . '/gallery/');

/* walk through directory till a file, depending on the timestamp, is found. */
while (false != ($file = readdir($handle))) {
if($file==$timestamp.".png" || $file==$timestamp.".jpeg" || $file==$timestamp.".jpg" || $file==$timestamp.".gif" || $file==$timestamp.".swf"){
$image['edit']=$file;
$image['file']=$source.'/gallery/'.$file;
/* to determine which file has to be removed and replaced.... */
/* ... and in which directory */
$image['source']=$source;
}
}

closedir($handle);

return $image;
}

public function getdescription($source, $timestamp){
$connection=new shared();
$connection->connect();

$descr=new mysql($source);
$query=$descr->select($timestamp, 'id');

while($myDescription=$descr->FetchArray($query)){
extract($myDescription);

if(!empty($id)){
$description['timestamp']=$id;
$description['descr']=$description;
}
}

return $description;
}

public function deletefiles($source, $timestamp){

#########
//new
#########

/* walk through directory till a file, depending on the timestamp, is found. */
$directory='public/content/' . $source . '/thumbs/';
$handle = opendir($directory);

while (false != ($file = readdir($handle))) {
if($file=="thumb_".$timestamp.".png" || $file=="thumb_".$timestamp.".jpeg" || $file=="thumb_".$timestamp.".jpg" || $file=="thumb_".$timestamp.".gif" || $file=="thumb_".$timestamp.".swf"){
if(!unlink($directory.$file)){
echo"Error deleting thumb, it can't be found. You are being redirected about 3 seconds...<br />";
echo"<meta http-equiv=\"refresh\" content=\"3; URL=".__ROOT.$_SESSION['back']."\" \>";
}
}
}

closedir($handle);

$directory='public/content/' . $source . '/gallery/';
$handle = opendir($directory);

/* walk through directory till a file, depending on the timestamp, is found. */
while (false != ($file = readdir($handle))) {
if($file==$timestamp.".png" || $file==$timestamp.".jpeg" || $file==$timestamp.".jpg" || $file==$timestamp.".gif" || $file==$timestamp.".swf"){
if(!unlink($directory.$file)){
echo"Error deleting image, it can't be found. You are being redirected about 3 seconds...<br />";
echo"<meta http-equiv=\"refresh\" content=\"3; URL=".__ROOT.$_SESSION['back']."\" \>";
}
}
}

closedir($handle);

return $source;
echo"<meta http-equiv=\"refresh\" content=\"0; URL=".__ROOT.$_SESSION['back']."\" \>";

}

}
?>
return $thumb;
return $image;
return $description;

Deze variabelen worden allemaal in een while-lus aangemaakt zonder dat er enige garantie is dat je met de code ALTIJD in de while lus terecht komt. Het kan dus heel goed zijn dat de variabelen niet bestaan. Sterker nog, die situatie doet zich al voor, zie de foutmeldingen.
Nou de variabelen krijgen ook een waarde in de while lus als ik ze echo dus de while statement en de if statement zijn allebei waar....
pgFrank schreef op 15.01.2009 19:03
return $thumb;
return $image;
return $description;

Deze variabelen worden allemaal in een while-lus aangemaakt zonder dat er enige garantie is dat je met de code ALTIJD in de while lus terecht komt. Het kan dus heel goed zijn dat de variabelen niet bestaan. Sterker nog, die situatie doet zich al voor, zie de foutmeldingen.


Nou de variabelen krijgen ook een waarde in de while lus als ik ze echo dus de while statement en de if statement zijn allebei waar.... snap wel wat je bedoelt... maar wat het nou veroorzaakt...
En wat geeft jou de zekerheid dat de loop minimaal 1x doorlopen wordt en dat er aan de voorwaarden in het if-statement voldaan wordt?

Als dat niet het geval is, zullen de betreffende variabelen niet bestaan en krijg je dus deze foutmelding...
Je komt pas in de lus wanneer de while true is. Wanneer deze false is, kom je nooit in de lus terecht en zullen de variabelen nooit worden aangemaakt. Zie de foutmelding.
Blanche schreef op 16.01.2009 13:16
En wat geeft jou de zekerheid dat de loop minimaal 1x doorlopen wordt en dat er aan de voorwaarden in het if-statement voldaan wordt?

Als dat niet het geval is, zullen de betreffende variabelen niet bestaan en krijg je dus deze foutmelding...


Dat weet ik omdat ik op regel 72 echo $thumb['file']; heb geprobeerd en dan geeft ie geeft ie wel degelijk de filenaam op het scherm weer
pgFrank schreef op 16.01.2009 13:17
Je komt pas in de lus wanneer de while true is. Wanneer deze false is, kom je nooit in de lus terecht en zullen de variabelen nooit worden aangemaakt. Zie de foutmelding.


Op regel 72 heb ik echo $thumb['file']; geprobeerd en dan geeft ie geeft ie wel degelijk de filenaam op het scherm weer
Ja, alléén als dat if-statement uitgevoerd wordt zal die variabele inderdaad wel bestaan. Maar wat geeft jou de zekerheid dat dat gebeurd?

ps. Sterker nog, het gebeurt blijkbaar niet. Zie de foutmelding...
Dat is IN die while lus.

Zoals men al zegt, zit je NIET ALTIJD IN die while lus, dus dan zijn die variabelen OOK NIET aangemaakt.
Blanche schreef op 16.01.2009 13:34
Ja, alléén als dat if-statement uitgevoerd wordt zal die variabele inderdaad wel bestaan. Maar wat geeft jou de zekerheid dat dat gebeurd?

ps. Sterker nog, het gebeurt blijkbaar niet. Zie de foutmelding...


Oké sterker nog: zelfs buiten de while loop doe ik: echo echo $thumb['file']; de variabele is wel degelijk gevuld want ik zie een waarde op het scherm. Maar tegelijkertijd bestaat diezelfde variabele op diezelfde regel niet zegt de foutmelding er onder.

Dus hij bestaat niet maar tegelijkertijd bestaat ie wel?

Reageren