PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Wed Oct 17, 2018 9:36 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: Offset problem
PostPosted: Thu Oct 20, 2005 1:01 am 
Offline
Forum Regular

Joined: Fri Jun 10, 2005 1:43 am
Posts: 592
Location: LT
I have problems with my client's host...

back_EN.php:
Syntax: [ Download ] [ Hide ]
//class.Database.php

$msg['NoDB'] = 'Unable to connect to database.';



//class.Authorization.php

$msg['InvalidLogin'] = 'Invalid username or password.';



//class.Validator.php

$msg['EmptyField'] = '<b>{field}</b> field is empty.';

$msg['InvalidField'] = '<b>{field}</b> field is invalid.';

/* ... */

index.php
Syntax: [ Download ] [ Hide ]
include(languages . '/back_EN.php'); //The file above, it includes fine, no errors



//Class includes



/* ... */



if ($authorization->error())

{

  $_SESSION['msg'] = $msg[$authorization->getError()]; //Error is here, $authorization->getError() IS 'InvalidLogin', I echoed it

  include('pages/index.php');

  exit;

}


I get Notice: Uninitialized string offset: 0 in ... . Can't I use $msg[$authorization->getError()]?? It works fine on my local machine.

---EDIT---
Sorry, this doesn't work, I accidently checked that on my local machine, so it doesn't apply to this host, it still doesn't work, even if pasted in index.php.
Quote:
The interesting thing is, that if I delete $msg['InvalidLogin'] = 'Invalid username or password.'; from the back_EN.php and paste it into index.php, then I get no error and it prints the message!

---EDIT---

I'm really not sure what is wrong here. Something unbelievable. Any info greatly appreciated.


Last edited by Ree on Thu Oct 20, 2005 6:26 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 1:24 am 
Offline
Neighborhood Spidermoddy
User avatar

Joined: Mon Mar 29, 2004 4:24 pm
Posts: 31559
Location: Bothell, Washington, USA
it would appear it believes $msg is a string.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 1:34 am 
Offline
Forum Regular

Joined: Fri Jun 10, 2005 1:43 am
Posts: 592
Location: LT
I have added $msg = array(); (I guess that's what you meant) at the top of the back_EN.php - no help. Damn, I'm not sure what to do, these kind of problems smurf me off so much! The host is running 4.3.11, could there be some prob here?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 5:01 am 
Offline
Jedi Mod
User avatar

Joined: Tue Dec 21, 2004 6:03 pm
Posts: 5263
Location: usrlab.com
What happens if you do print_r($msg); immediately before your "if ($authorization->error())" block? It looks to me like something has overwritten $msg..


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 6:01 am 
Offline
Forum Regular

Joined: Fri Jun 10, 2005 1:43 am
Posts: 592
Location: LT
It does absolutely nothing, prints nothing.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 6:12 am 
Offline
Forum Regular

Joined: Thu Apr 24, 2003 6:51 am
Posts: 416
Location: The Netherlands
Looking at your error: Uninitialized string offset: 0 ....

I think he try'ing to do : $_SESSION['msg'] = $msg[0];

So $authorization->getError() return's 0?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 6:13 am 
Offline
Forum Regular

Joined: Fri Jun 10, 2005 1:43 am
Posts: 592
Location: LT
No, as I mentioned above $authorization->getError() IS 'InvalidLogin', I echoed it:
Syntax: [ Download ] [ Hide ]
if ($authorization->error())

{

  echo $authorization->getError(); //Outputs 'InvalidLogin'

  $_SESSION['msg'] = $msg[$authorization->getError()]; //The prob here

  include('pages/index.php');

  exit;

}

I even tried this:
Syntax: [ Download ] [ Hide ]
if ($authorization->error())

{

  $err_id = $authorization->getError();

  echo $err_id; //Outputs 'InvalidLogin'

  $_SESSION['msg'] = $msg[$err_id]; //The prob still there

  include('pages/index.php');

  exit;

}

I have NO clue what is wrong...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 8:29 am 
Offline
Neighborhood Spidermoddy
User avatar

Joined: Mon Mar 29, 2004 4:24 pm
Posts: 31559
Location: Bothell, Washington, USA
var_dump($msg)

I'll bet you see
Syntax: [ Download ] [ Hide ]
String(0) ""
or similar


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 9:03 am 
Offline
Forum Regular

Joined: Fri Jun 10, 2005 1:43 am
Posts: 592
Location: LT
In my first post, the POST of the form goes to the script itself, that is, to index.php

Here's something I tried for testing, pretty much the same situation as in my first post (the POST goes to the script itself).

test.php
Syntax: [ Download ] [ Hide ]
<?php

session_start();

ini_set('display_errors', 1);

error_reporting(E_ALL);

?>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

</head>

<body>

<?php



include('lib/class.Tester.php');

include('lang/back_EN.php');



$_SESSION['msg'] = '';



if (!isset($_POST['sub']))

{

  include('pages/test.php');

  exit;

}



$tester = &new Tester();

$tester->setError('InvalidLogin');



if ($tester->error())

{

  $_SESSION['msg'] = $msg[$tester->getError()];

  include('pages/test.php');

}



?>

</body>

</html>

lang/back_EN.php
Syntax: [ Download ] [ Hide ]
<?php



//class.Database.php

$msg['NoDB'] = 'Unable to connect to database.';



//class.Authorization.php

$msg['InvalidLogin'] = 'Invalid username or password.';



//class.Validator.php

$msg['EmptyField'] = '<b>{field}</b> field is empty.';

$msg['InvalidField'] = '<b>{field}</b> field is invalid.';



/* ... */



?>

lib/class.Tester.php
Syntax: [ Download ] [ Hide ]
<?php



class Tester

{

  var $error;



  function Tester()

  {

    $this->error = '';

  }



  function setError($error)

  {

    $this->error = $error;

  }



  function getError()

  {

    return $this->error;

  }



  function error()

  {

    return (bool)$this->error;

  }

}



?>

pages/test.php
Syntax: [ Download ] [ Hide ]
<br />

<br />

<br />

<?php

echo $_SESSION['msg'];

$_SESSION['msg'] = '';

?>

<br />

<br />

<form method="post" action="test.php">

  <table>

    <tr>

      <td><input type="submit" value="Submit" name="sub" /></td>

    </tr>

  </table>

</form>

On my local machine, I do get the message ('Invalid username or password.'), on the host I get the same uninitialized offset error. Maybe you will be able to spot the problem (if the code has a flaw).

Also, you can check the problem live at http://test.keliozenklai.lt/test2/test.php . It uses exactly the same code as in this post.


Last edited by Ree on Thu Oct 20, 2005 11:52 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 10:57 am 
Offline
Forum Regular

Joined: Fri Jun 10, 2005 1:43 am
Posts: 592
Location: LT
Can you spot something wrong with my test script above? What could be the reason that it doesn't work on the host, but it does on my comp?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 16, 2005 2:00 pm 
Offline
Forum Contributor

Joined: Wed Jan 14, 2004 11:21 am
Posts: 313
Location: planet earth
-
How to get rid of that "Notice: Uninitialized string offset: 0"?


I test a string like that, if it is set (later empty) and then "do something";


Syntax: [ Download ] [ Hide ]
if (!isset($para['text'])) {
$para['text']='';
}

if (!empty($para['text'])) {
vardump($para['text']);
do something... e.g. print $para['text'];
}


Now line "do something" throws the error. Normally $para['text'] is a string, but how to circumvent the notice, if it is not set? (vardump shows 0 "" in this case)


I only have this problem with PHP v5.0.5,
not with PHP v5.0.4 or PHP v4.xx

djot
-


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Exabot [Bot] and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group