Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7183167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:55:29+00:00 2026-05-28T17:55:29+00:00

Now I am dealing with PHP but I`ve stucked with a strange issue: I

  • 0

Now I am dealing with PHP but I`ve stucked with a strange issue:
I am making a simple foo for string length:

function slen($str) {
  $len;
  for ( $len=0; $str[$len]; $len++ ) {
          /* while tehre is a symbol in $str continue counting, old C metnod */
   }
   return (int)$len;
}

it`s on as a code, and outputs the length but it booms with an PHP warning message :
PHP Notice: Uninitialized string offset: 3 in /home/ilian/Desktop/SERVER/ex4.php on line 5
And on my line 5 is the for loop initialization. So I got that PHP might be confusing by not knowing what kind of variables it checks for TRUE in that array because it can be
“Array”, “HELLO”, “MESS”, 50 and length is 4 which is correct, but in the case I aam checking a simple string for length. Any easygoing explanation?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T17:55:31+00:00Added an answer on May 28, 2026 at 5:55 pm

    The problem is that at some point your condition ($str[$len]) will try to access an offset beyond the end of the string. That’s your stopping condition, but that stopping condition throws the notice, since accessing an undefined offset is considered an error (and rightly so). You’ll need to check whether the offset exists using isset($str[$len]), which does not throw a notice.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm dealing with the 3-tier architecture PHP website. Now I need to redesign it
I'm dealing with PHP grammar and I want to pass to my function the
I am dealing with a very strange and rather simple problem about 2 days
I'm now dealing with uri like /page.html?k1=1&k2=2 $str = preg_replace('/[&\?]' . $k . '=[^&]*/',,$str);
I found a site with some complicated C puzzles. Right now I'm dealing with
Now this is .NET but I am sure the principal should apply to all
I'm really unsure if this is even possible but we have an issue where
I've been researching this on and off for a number of months now, but
I'm now dealing with twitter API and my app posts some text to twitter.
Regular Expressions are a complete void for me. I'm dealing with one right now

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.