Re: [PHP] Re: Illegal string offset error in array

2005-03-28 Thread Johannes Findeisen
Hello Jasper and Rasmus,

thanks for reply! I have found out why this does not work. Take a look below.

On Monday 28 March 2005 02:33, Rasmus Lerdorf wrote:
> Jasper Bryant-Greene wrote:
> > Rasmus Lerdorf wrote:
>  Jasper Bryant-Greene wrote:
> > You can't access string offsets with square brackets [] in PHP5.
> > You need to use curly braces {} instead.

I have replaced all square brackets with curly braces when using string 
offsets. This didn't helped but worked on PHP4 and 5.

> > Yes, but he's talking about PHP5. He probably has E_STRICT on, which is
> > why he's getting that error.
> >
> > I was telling him to use the correct syntax, which will cause him to not
> > get that error.

I have E_STRICT on but the same behaviour with E_STRICT off

> I know we are talking about PHP5, and that syntax does not throw an
> E_STRICT error.
>

Right!!

Okay, lets see my original function again (copied from first post):

function getNavigationContent($content_path) {
  $i = 0;
  $dir = opendir($content_path);
  while ($file = readdir ($dir))  Â{
    if ($file != "." && $file != ".." && !in_array($file, explode(',', 
$this->arrConf['default_filtered_files']))) {
      $arrAvailableContent[$i] = $file;
      if(is_dir($content_path . $file)) {
        echo $n = 0;
        $subdir = opendir($content_path . $file);
        while ($subfile = readdir ($subdir)) Â{
          if ($subfile != "." && $subfile != "..") {
          
            /*
            Â* This line does not work in PHP5 cause 
off an 
illegal string offset in an array ERROR
            Â*/
            
$arrAvailableContent[$i]['submenu'][$n]['file'] = 
$subfile;
          $n++;
          }
        }
        closedir($subdir);
      }
    $i++;
    }
  }
  closedir($dir);
  return $arrAvailableContent;
}

In the code take a look at the following line:

$arrAvailableContent[$i] = $file;

I am assiging a string to the var $arrAvailableContent[$i] .

Now lets take a look at the line i thought which was wrong:

$arrAvailableContent[$i]['submenu'][$n]['file'] = $subfile;

Now i am assigning a string to $arrAvailableContent[$i]['submenu'][$n]['file'] 
and this is what doesn't work. Now i have var_dump'ed all the arrays and i 
found out, that there are no values in $arrAvailableContent[$i]['submenu']
[$n]['file'] in PHP4. In PHP5 the script exits because of a Fatal Error.  But 
if i set the line:

$arrAvailableContent[$i] = $file;

To:

$arrAvailableContent[$i]['file'] = $file;

Everything works fine in PHP4 and PHP5. 

My function now looks like this:

function getNavigationContent($content_path) {
  $i = 0;
  $dir = opendir($content_path);
  while ($file = readdir ($dir))  Â{
    if ($file != "." && $file != ".." && !in_array($file, explode(',', 
$this->arrConf['default_filtered_files']))) {
      $arrAvailableContent[$i]{'file'} = $file;
      if(is_dir($content_path . $file)) {
        echo $n = 0;
        $subdir = opendir($content_path . $file);
        while ($subfile = readdir ($subdir)) Â{
          if ($subfile != "." && $subfile != "..") {
          
            
$arrAvailableContent[$i]{'submenu'}[$n]{'file'} = 
$subfile;
          $n++;
          }
        }
        closedir($subdir);
      }
    $i++;
    }
  }
  closedir($dir);
  return $arrAvailableContent;
}

This works in PHP4 (4.3.10) and PHP5 (5.0.3)!

Okay, after this my array doesn't look like the application wants it but this 
is because i never had this problem before and it should be fixed at all. I 
can change it quickly in my app since it is designed very clean but i just 
wanted you to know my conclusion.

I have developed many lines of code in PHP4 in the last years but this weekend 
i gave PHP5 a try. I must say i am impressed. PHP4 really is missing some 
features but it is great too. Thanks Rasmus for inventing this scripting 
language. I will become a better PHP programmer just only with the new 
features in PHP5!

Have a nice day!

Regards
-- 
# Johannes Findeisen

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Illegal string offset error in array

2005-03-27 Thread James Kaufman
On Mon, Mar 28, 2005 at 11:29:28AM +1200, Jasper Bryant-Greene wrote:
> Rasmus Lerdorf wrote:
> >>>Jasper Bryant-Greene wrote:
> You can't access string offsets with square brackets [] in PHP5. You 
> need to use curly braces {} instead.
> >>>
> >>>Not sure where you got that idea.  This is not true.
> >>>
> >>>-Rasmus
> >>
> >>Actually, it is. See the following URL:
> >>
> >>http://www.php.net/manual/en/language.types.string.php#language.types.string.substr
> >> 
> >
> >Yes, please read that link again.  The syntax is deprecated.  That 
> >doesn't mean it doesn't work as you indicated.  If we broke this most of 
> >the scripts written for PHP4 would break.
> >
> >-Rasmus
> 
> Yes, but he's talking about PHP5. He probably has E_STRICT on, which is
> why he's getting that error.
> 
> I was telling him to use the correct syntax, which will cause him to not
> get that error.
> 
> Best regards
> 
> -- 
> Jasper Bryant-Greene
> Cabbage Promotions
> www:   www.cabbage.co.nz
> email: [EMAIL PROTECTED]
> phone: 021 232 3303
> 
> public key:  Jasper Bryant-Greene <[EMAIL PROTECTED]> keyID 0E6CDFC5
> fingerprint: 2313 5641 F8F6 5606 8844 49C0 1D6B 2924 0E6C DFC5
> 

You do realize you're arguing with Rasmus, right?

-- 
Jim Kaufman
Linux Evangelist
public key 0x6D802619, CISSP# 65668

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Illegal string offset error in array

2005-03-27 Thread Rasmus Lerdorf
Jasper Bryant-Greene wrote:
Rasmus Lerdorf wrote:
Jasper Bryant-Greene wrote:
You can't access string offsets with square brackets [] in PHP5. 
You need to use curly braces {} instead.

Not sure where you got that idea.  This is not true.
-Rasmus

Actually, it is. See the following URL:
http://www.php.net/manual/en/language.types.string.php#language.types.string.substr 

Yes, please read that link again.  The syntax is deprecated.  That 
doesn't mean it doesn't work as you indicated.  If we broke this most 
of the scripts written for PHP4 would break.

-Rasmus

Yes, but he's talking about PHP5. He probably has E_STRICT on, which is
why he's getting that error.
I was telling him to use the correct syntax, which will cause him to not
get that error.
I know we are talking about PHP5, and that syntax does not throw an 
E_STRICT error.

-Rasmus
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Re: Illegal string offset error in array

2005-03-27 Thread Jasper Bryant-Greene
Rasmus Lerdorf wrote:
Jasper Bryant-Greene wrote:
You can't access string offsets with square brackets [] in PHP5. You 
need to use curly braces {} instead.
Not sure where you got that idea.  This is not true.
-Rasmus
Actually, it is. See the following URL:
http://www.php.net/manual/en/language.types.string.php#language.types.string.substr 
Yes, please read that link again.  The syntax is deprecated.  That 
doesn't mean it doesn't work as you indicated.  If we broke this most of 
the scripts written for PHP4 would break.

-Rasmus
Yes, but he's talking about PHP5. He probably has E_STRICT on, which is
why he's getting that error.
I was telling him to use the correct syntax, which will cause him to not
get that error.
Best regards
--
Jasper Bryant-Greene
Cabbage Promotions
www:   www.cabbage.co.nz
email: [EMAIL PROTECTED]
phone: 021 232 3303
public key:  Jasper Bryant-Greene <[EMAIL PROTECTED]> keyID 0E6CDFC5
fingerprint: 2313 5641 F8F6 5606 8844 49C0 1D6B 2924 0E6C DFC5
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Re: Illegal string offset error in array

2005-03-27 Thread Rasmus Lerdorf
Jasper Bryant-Greene wrote:
Rasmus Lerdorf wrote:
Jasper Bryant-Greene wrote:
You can't access string offsets with square brackets [] in PHP5. You 
need to use curly braces {} instead.

Not sure where you got that idea.  This is not true.
-Rasmus

Actually, it is. See the following URL:
http://www.php.net/manual/en/language.types.string.php#language.types.string.substr 
Yes, please read that link again.  The syntax is deprecated.  That 
doesn't mean it doesn't work as you indicated.  If we broke this most of 
the scripts written for PHP4 would break.

-Rasmus
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Re: Illegal string offset error in array

2005-03-27 Thread Jasper Bryant-Greene
Rasmus Lerdorf wrote:
Jasper Bryant-Greene wrote:
You can't access string offsets with square brackets [] in PHP5. You 
need to use curly braces {} instead.
Not sure where you got that idea.  This is not true.
-Rasmus
Actually, it is. See the following URL:
http://www.php.net/manual/en/language.types.string.php#language.types.string.substr
Best regards
--
Jasper Bryant-Greene
Cabbage Promotions
www:   www.cabbage.co.nz
email: [EMAIL PROTECTED]
phone: 021 232 3303
public key:  Jasper Bryant-Greene <[EMAIL PROTECTED]> keyID 0E6CDFC5
fingerprint: 2313 5641 F8F6 5606 8844 49C0 1D6B 2924 0E6C DFC5
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Re: Illegal string offset error in array

2005-03-27 Thread Rasmus Lerdorf
Jasper Bryant-Greene wrote:
Johannes Findeisen wrote:
Hello all,
sorry if this has been asked allready but i didn't find any usefull 
information in the web.

Why is this function not working in PHP5?
 [snip]
/*
 * This line does not work in PHP5 cause off 
an illegal string offset in an array ERROR
 */

$arrAvailableContent[$i]['submenu'][$n]['file'] = $subfile;
 [snip]
Can someone help?

You can't access string offsets with square brackets [] in PHP5. You 
need to use curly braces {} instead.
Not sure where you got that idea.  This is not true.
-Rasmus
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Illegal string offset error in array

2005-03-27 Thread Jasper Bryant-Greene
Johannes Findeisen wrote:
Hello all,
sorry if this has been asked allready but i didn't find any usefull 
information in the web.

Why is this function not working in PHP5?
 [snip]

/*
 * This line does not work in PHP5 cause off an 
illegal string offset in an array ERROR
 */
$arrAvailableContent[$i]['submenu'][$n]['file'] = 
$subfile;
 [snip]
Can someone help?
You can't access string offsets with square brackets [] in PHP5. You 
need to use curly braces {} instead.

Square brackets [] for arrays, curly braces {} for string offsets.
--
Jasper Bryant-Greene
Cabbage Promotions
www:   www.cabbage.co.nz
email: [EMAIL PROTECTED]
phone: 021 232 3303
public key:  Jasper Bryant-Greene <[EMAIL PROTECTED]> keyID 0E6CDFC5
fingerprint: 2313 5641 F8F6 5606 8844 49C0 1D6B 2924 0E6C DFC5
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php