Uninitialized string offset php

I have a form that users fill out, and on the form there are multiple identical fields, like "project name", "project date", "catagory", etc. Based on how many forms a user is submitting, my goal is to:

  1. loop over the number of forms
  2. create individual SQL insert statements

However, PHP throws me a NOTICE that I don’t seem to understand:

Notice:

Notice: Uninitialized string offset: 1 . dataPasser.php on line 90

PHP

There are references to this issue I am having, but they are not exact and I am having trouble deducing where the actual problem stems from. I would greatly appreciate any help in understanding what is causing the array to not initialize properly.

Comments

Copy link Quote reply

FMaz008 commented Nov 28, 2011

When I run phploc against the vendor/ folder of symfony2 ( in wich I do have bundle that are not part of the standard edition ), I get about 10 PHP notice:

Uninitialized string offset: 1 in PHPLOC/Analyser.php on line 602

I’ve edited the PHPLOC/Analyser.php file to help debug the issue:

And the output is:
bool(false)
int(51)
string(1) "<"

I’ve also done a debug_print_backtrace:
#0 PHPLOC_Analyser->getClassName()
#1 PHPLOC_Analyser->countFile() called at [/usr/local/Cellar/php/5.3.8/lib/php/PHPLOC/Analyser.php:170]
#2 PHPLOC_Analyser->countFiles() called at [/usr/local/Cellar/php/5.3.8/lib/php/PHPLOC/TextUI/Command.php:220]
#3 PHPLOC_TextUI_Command::main() called at [/usr/local/Cellar/php/5.3.8/bin/phploc:51]

This comment has been minimized.

Copy link Quote reply

GaryJones commented Nov 4, 2012

In version 1.7.1 of phploc, this is now line 611.

This comment has been minimized.

Copy link Quote reply

mbadolato commented Nov 9, 2012

From a recent Jenkins run:

17:35:55 phploc:
17:35:55 [exec] phploc 1.7.1 by Sebastian Bergmann.
17:35:55 [exec]
17:36:40 [exec] PHP Notice: Uninitialized string offset: 1 in /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php on line 611
17:36:40 [exec] PHP Stack trace:
17:36:40 [exec] PHP 1.

() /usr/local/bin/phploc:0
17:36:40 [exec] PHP 2. SebastianBergmannPHPLOCTextUICommand->main() /usr/local/bin/phploc:52
17:36:40 [exec] PHP 3. SebastianBergmannPHPLOCAnalyser->countFiles() /usr/local/share/pear/SebastianBergmann/PHPLOC/TextUI/Command.php:209
17:36:40 [exec] PHP 4. SebastianBergmannPHPLOCAnalyser->countFile() /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php:172
17:36:40 [exec] PHP 5. SebastianBergmannPHPLOCAnalyser->getClassName() /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php:373
17:36:40 [exec] PHP Notice: Uninitialized string offset: 1 in /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php on line 611
17:36:40 [exec] PHP Stack trace:
17:36:40 [exec] PHP 1.
() /usr/local/bin/phploc:0
17:36:40 [exec] PHP 2. SebastianBergmannPHPLOCTextUICommand->main() /usr/local/bin/phploc:52
17:36:40 [exec] PHP 3. SebastianBergmannPHPLOCAnalyser->countFiles() /usr/local/share/pear/SebastianBergmann/PHPLOC/TextUI/Command.php:209
17:36:40 [exec] PHP 4. SebastianBergmannPHPLOCAnalyser->countFile() /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php:172
17:36:40 [exec] PHP 5. SebastianBergmannPHPLOCAnalyser->getClassName() /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php:373
17:36:40 [exec] PHP Notice: Uninitialized string offset: 1 in /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php on line 611
17:36:40 [exec] PHP Stack trace:
17:36:40 [exec] PHP 1.
() /usr/local/bin/phploc:0
17:36:40 [exec] PHP 2. SebastianBergmannPHPLOCTextUICommand->main() /usr/local/bin/phploc:52
17:36:40 [exec] PHP 3. SebastianBergmannPHPLOCAnalyser->countFiles() /usr/local/share/pear/SebastianBergmann/PHPLOC/TextUI/Command.php:209
17:36:40 [exec] PHP 4. SebastianBergmannPHPLOCAnalyser->countFile() /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php:172
17:36:40 [exec] PHP 5. SebastianBergmannPHPLOCAnalyser->getClassName() /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php:373
17:36:40 [exec] PHP Notice: Uninitialized string offset: 1 in /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php on line 611
17:36:40 [exec] PHP Stack trace:
17:36:40 [exec] PHP 1.
() /usr/local/bin/phploc:0
17:36:40 [exec] PHP 2. SebastianBergmannPHPLOCTextUICommand->main() /usr/local/bin/phploc:52
17:36:40 [exec] PHP 3. SebastianBergmannPHPLOCAnalyser->countFiles() /usr/local/share/pear/SebastianBergmann/PHPLOC/TextUI/Command.php:209
17:36:40 [exec] PHP 4. SebastianBergmannPHPLOCAnalyser->countFile() /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php:172
17:36:40 [exec] PHP 5. SebastianBergmannPHPLOCAnalyser->getClassName() /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php:373
17:36:40 [exec] PHP Notice: Uninitialized string offset: 1 in /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php on line 611
17:36:40 [exec] PHP Stack trace:
17:36:40 [exec] PHP 1.
() /usr/local/bin/phploc:0
17:36:40 [exec] PHP 2. SebastianBergmannPHPLOCTextUICommand->main() /usr/local/bin/phploc:52
17:36:40 [exec] PHP 3. SebastianBergmannPHPLOCAnalyser->countFiles() /usr/local/share/pear/SebastianBergmann/PHPLOC/TextUI/Command.php:209
17:36:40 [exec] PHP 4. SebastianBergmannPHPLOCAnalyser->countFile() /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php:172
17:36:40 [exec] PHP 5. SebastianBergmannPHPLOCAnalyser->getClassName() /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php:373

Читайте также:  Xiaomi redmi note 6 pro мтс

Also, phploc is reporting as 1.7,1. Doing a pear update says 1.7.2 is already installed. Removing it (and verifying that it’s gone) and doing a fresh pear update still shows the same thing. I also grabbed the .phar per the instructions in the docs, and that version is reporting as 1.7.1 also. So sounds like a version string wasn’t updated

This comment has been minimized.

Copy link Quote reply

sebastianbergmann commented Nov 9, 2012

I need a file that triggers this to debug the issue properly.

This comment has been minimized.

Copy link Quote reply

mbadolato commented Nov 9, 2012

TL;DR: Couldn’t isolate the file but DID find a bug with —exclude. The file causing the problem is one that should have been excluded from phploc. All of this is detailed below The —exclude bug happened somewhere after the 1.6.4 release.

Ok, I was thinking that it was throwing that output before it started processing any files. Further testing after your request for a file, shows that indeed it is something in a file throwing the code. Unfortunately, I don’t have an example to provide since the error messages don’t provide any info as to which file caused the error, and it’s a very large tree.

Here is one thing I did find interesting however. This is the applicable config portion from my build (this is on a Symfony2 project, though that really shouldn’t matter other than for directory layout informational purposes):

This is the equivilent on the command line:

Running from command line DOES give me the same error output. I started trying to isolate where it was coming from by running on individual directories. Given the exclusions above, the only applicable directory would be my src/ directory, and when running

Читайте также:  Core 2 duo t8400

It ran cleanly. So, I started running it on the other directories (i.e., the excluded directories). The error appeared when I ran it on /vendor. So, it is somewhere within the large /vendor tree (Symfony framework, Doctrine framework, various bundles etc).

That’s all well and good but. Given that vendor/ was originally part of the —exclude directives, why is phploc still parsing that directory? That would seem to be a (unrelated) phplog bug whereby excluded directories are being parsed (even if the statistics from that directory are not being counted, which , in looking at my numbers, they ARE being included).

Running with only vendors in the exclude list, produced the same thing:

This is the directory structure:

on any other directory there (app, bin, build, src, web) produces clean results with correct counts, or "No files found to scan" as appropriate.

As I was typing this out, I noticed that phploc was upgraded to 1.7.3. Tested with that and same results.

One last test, and this may help you out. My development box is still running phploc 1.6.4. Out of curiosity, I ran this:

and it runs clean, as you can see, including the actual statistic counts.

Running that EXACT same command on the exact same source tree on the box with 1.7.3:

So the exclusion is definitely different since 1.6.4

The box with 1.7.3:

The box with 1.6.4:

There are some slight variations on the actual php and pear modules installed on each box, however. I can provide a list if that would help.

Please let me know if I can provide any other information!
—mark

Читайте также:  Intel r sandybridge ivybridge graphics chipset

a Ad d w cbf b G y ntNF td J Ljf e nRH t ic B clH r KXQF a gfhAh i vnveT n w s g

Answer Wiki

That happens when you are trying to access character of the string by sequence number, but string is shorter than your given sequence number.

When you have string stored inside variable

And you are trying to access it as if it were array of characters

You would get an output of first character of string, in this case, an “f”.

This string is 3 characters long, when you will be trying to access 4th character with (first character sequence number is zero)

You will get “Uninitialized string offset” error, because there is no 4th letter in give.

Rate this post

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *