This is a discussion on class problem within the PHP Language forums, part of the PHP Programming Forums category; I get an error: Fatal error: Call to a member function on a non-object in It s telling me ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I get an error:
Fatal error: Call to a member function on a non-object in It s telling me that $objImage: is not an object. Although i made it an object in the constructor. Someone can help me out? kind regards Stijn The errorline is: $objImage->createImage($index); include_once('class.UploadPicture.php'); class Album { var $objImage; function Album($width) //constructor { $objImage = new UploadPicture($width,''); } function putImage($index) { $objImage->createImage($index); } } ?> |
|
|||
|
Stijn Goris wrote:
> I get an error: > Fatal error: Call to a member function on a non-object in > > It s telling me that $objImage: is not an object. Although i made it an > object in the constructor. Someone can help me out? > Try to print out the $objImage. The problem is probably on the: *$objImage = new UploadPicture($width,'');* > > > The errorline is: $objImage->createImage($index); > > include_once('class.UploadPicture.php'); > class Album > { > var $objImage; > > function Album($width) //constructor > { > $objImage = new UploadPicture($width,''); if( !$objImage ) echo 'objImage is null!'; > } > > function putImage($index) > { > $objImage->createImage($index); > } > } > ?> > > -Ema- |
|
|||
|
"-Ema-" <a@b.c> wrote in message news:a2vRb.290117$e6.11243424@twister2.libero.it.. . > Stijn Goris wrote: > > > I get an error: > > Fatal error: Call to a member function on a non-object in > > > > It s telling me that $objImage: is not an object. Although i made it an > > object in the constructor. Someone can help me out? > > > Try to print out the $objImage. > The problem is probably on the: > *$objImage = new UploadPicture($width,'');* > > > > > > The errorline is: $objImage->createImage($index); > > > > include_once('class.UploadPicture.php'); > > class Album > > { > > var $objImage; > > > > function Album($width) //constructor > > { > > $objImage = new UploadPicture($width,''); > if( !$objImage ) > echo 'objImage is null!'; > > } > > > > function putImage($index) > > { > > $objImage->createImage($index); > > } > > } > > ?> > > > > > > -Ema- > The object is created correctly but seems to be unknown in the putImage function. When I do function Album($width) //constructor { $this->setCurrentPeriod(); $objImage = new UploadPicture($width,''); $objImage->createImage(0); } It works but when I do function Album($width) //constructor { $this->setCurrentPeriod(); $objImage = new UploadPicture($width,''); $this->putImage(1); } function putImage($index) { $objImage->createImage(1); } I get the error: Fatal error: Call to a member function on a non-object Someone knows what the problem is? kind regards Stijn |
|
|||
|
Stijn Goris wrote:
> "-Ema-" <a@b.c> wrote in message > news:a2vRb.290117$e6.11243424@twister2.libero.it.. . > >>Stijn Goris wrote: >> >> >>>I get an error: >>>Fatal error: Call to a member function on a non-object in >>> >>>It s telling me that $objImage: is not an object. Although i made it an >>>object in the constructor. Someone can help me out? >>> >> >>Try to print out the $objImage. >>The problem is probably on the: >>*$objImage = new UploadPicture($width,'');* >> >>> >>>The errorline is: $objImage->createImage($index); >>> >>>include_once('class.UploadPicture.php'); >>>class Album >>>{ >>> var $objImage; >>> >>> function Album($width) //constructor >>> { >>> $objImage = new UploadPicture($width,''); >> >> if( !$objImage ) >>echo 'objImage is null!'; >> >>> } >>> >>> function putImage($index) >>> { >>> $objImage->createImage($index); >>> } >>>} >>>?> >>> >>> >>-Ema- >> > > > The object is created correctly but seems to be unknown in the putImage > function. > When I do > > function Album($width) //constructor > { > $this->setCurrentPeriod(); > $objImage = new UploadPicture($width,''); > $objImage->createImage(0); > } > > It works > > but when I do > > function Album($width) //constructor > { > $this->setCurrentPeriod(); > $objImage = new UploadPicture($width,''); > $this->putImage(1); > } > > function putImage($index) > { > $objImage->createImage(1); > } > > I get the error: Fatal error: Call to a member function on a non-object > > Someone knows what the problem is? > kind regards > Stijn > > > > > Yeah! I'm stupid! This is a tivial error. You must referentiate always your member variables with $this. So your class is: class Album { var $objImage; function Album($width) //constructor { $this->objImage = new UploadPicture($width,''); } function putImage($index) { $this->objImage->createImage($index); } } see you. -Ema- |
|
|||
|
"-Ema-" <a@b.c> wrote in message news:rWvRb.290252$e6.11245969@twister2.libero.it.. . > Stijn Goris wrote: > > > "-Ema-" <a@b.c> wrote in message > > news:a2vRb.290117$e6.11243424@twister2.libero.it.. . > > > >>Stijn Goris wrote: > >> > >> > >>>I get an error: > >>>Fatal error: Call to a member function on a non-object in > >>> > >>>It s telling me that $objImage: is not an object. Although i made it an > >>>object in the constructor. Someone can help me out? > >>> > >> > >>Try to print out the $objImage. > >>The problem is probably on the: > >>*$objImage = new UploadPicture($width,'');* > >> > >>> > >>>The errorline is: $objImage->createImage($index); > >>> > >>>include_once('class.UploadPicture.php'); > >>>class Album > >>>{ > >>> var $objImage; > >>> > >>> function Album($width) //constructor > >>> { > >>> $objImage = new UploadPicture($width,''); > >> > >> if( !$objImage ) > >>echo 'objImage is null!'; > >> > >>> } > >>> > >>> function putImage($index) > >>> { > >>> $objImage->createImage($index); > >>> } > >>>} > >>>?> > >>> > >>> > >>-Ema- > >> > > > > > > The object is created correctly but seems to be unknown in the putImage > > function. > > When I do > > > > function Album($width) //constructor > > { > > $this->setCurrentPeriod(); > > $objImage = new UploadPicture($width,''); > > $objImage->createImage(0); > > } > > > > It works > > > > but when I do > > > > function Album($width) //constructor > > { > > $this->setCurrentPeriod(); > > $objImage = new UploadPicture($width,''); > > $this->putImage(1); > > } > > > > function putImage($index) > > { > > $objImage->createImage(1); > > } > > > > I get the error: Fatal error: Call to a member function on a non-object > > > > Someone knows what the problem is? > > kind regards > > Stijn > > > > > > > > > > > Yeah! I'm stupid! This is a tivial error. You must referentiate always > your member variables with $this. So your class is: > class Album > { > var $objImage; > > function Album($width) //constructor > { > $this->objImage = new UploadPicture($width,''); > } > > function putImage($index) > { > $this->objImage->createImage($index); > } > } > > see you. > -Ema- > thanks, I should hhave seen it |