For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > May 2007 > Uninitialized string offset









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Uninitialized string offset
misiek

2007-05-03, 6:57 pm

Not sure what causes this errro..!


$this->text = 'w';
$i = 0;
$token = '';

while ($this->text{$i} != null) // <= Line #37
{
// some code
$i++;
}



Uninitialized string offset: 1 in
/home/misiek/workspace/emailpower/app/models/text_construct.php on line 37


Use PHP 5.2

Thanks for help
ZeldorBlat

2007-05-03, 6:57 pm

On May 3, 11:29 am, misiek <michal_augustyn...@gazeta.pl> wrote:
> Not sure what causes this errro..!
>
> $this->text = 'w';
> $i = 0;
> $token = '';
>
> while ($this->text{$i} != null) // <= Line #37
> {
> // some code
> $i++;
> }
>
> Uninitialized string offset: 1 in
> /home/misiek/workspace/emailpower/app/models/text_construct.php on line 37
>
> Use PHP 5.2
>
> Thanks for help


You get that error because the string only has 1 character (at index
0) so there is no character at index 1. Try this instead:

while($i < strlen($this->text)) {
//some code
$i++;
}

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com