Illegal Offset Type For Array. Object To Integer Convertion

Jul 27, 2006

The code is as ...

$folderlistfile = $path."xmlfile.xml";

/*

<list>
<details id="2">
<name>Books</name>
<mainid>0</mainid>
</details>
<details id="1003">
<name>CDs</name>
<mainid>0</mainid>
</details>
</list>

*/

$list = simplexml_load_file($folderlistfile);

foreach($list as $sno=>$details) {
if($details->isdeletable) {
if($details->mainid) {

echo "<br /mainid = ".$details->mainid." : id =
".$details['id']." ";
var_dump($details->mainid);
$mainid = $details->mainid;
settype($mainid, "integer");
var_dump($mainid);

// I want to save the details in an array
//$listarr[$mainid][] = $details['id']; //Warning: Illegal offset
type
//$listarr[$details->mainid][] = $details['id']; //Warning: Illegal
offset type
}
}
}

echo, var_dump will output as follow ...

mainid = 0 : id = 2
object(SimpleXMLElement)#5 (1) { [0]= string(1) "0" }
UNKNOWN:0

mainid = 0 : id = 1003
object(SimpleXMLElement)#4 (1) { [0]= string(1) "0" }
UNKNOWN:0

Both of this generate the error : Warning: Illegal offset type

$listarr[$mainid][] = $details['id']; //Warning: Illegal offset type
$listarr[$details->mainid][] = $details['id']; //Warning: Illegal
offset type

and page doesn't execute furthur of this line.

I suppose it is because the array key is an object. How do I convert it
to integer.

print_r($details->mainid) displays SimpleXMLElement Object ( [0] =0
)
print_r($mainid) : nothing is displyed. even mainid = 0 : id = 2 is
not displayed.


System: free bsd, php 5

As is mentioned in the code, I want to craete an array as

either
$listarr[$mainid][] = $details['id']; //Warning: Illegal
offset type
or
$listarr[$details->mainid][] = $details['id']; //Warning:
Illegal offset type

ADVERTISEMENT

Illegal Offset Type?

Jul 15, 2005

I am getting the following warning:

Warning: Illegal offset type in C:path on line 17

there is nothing on line 17, so I started looking back... everything lools fine. What am I missing? Code:

View 3 Replies View Related

SimpleXMLElement And Warning: Illegal Offset Type?

Mar 2, 2011

Warning: Illegal offset type i have this var from an xml output

var_dump($key);
its give me
object(SimpleXMLElement)#11 (1) { [0]=> string(5) "Cairo" }

now i want make "Cairo" as a key to get its value like

$lang[] = array('Cairo' = "Cairo city");

the error appear when do this

echo $lang[$key];

and its give me the "Warning: Illegal offset type" because of the key is SimpleXMLElementhow i can make it normal var?

View 1 Replies View Related

Warning: "Illegal Offset Type In <file Location>example.php"

Dec 17, 2010

I've been having considerable trouble trying to figure out why my arrays weren't working as expected. I was using code functionally the same as the code below, but it was silently failing on me in my program, so I wrote an isolated test case using the same types of data and syntax and got the errors about illegal offset types.

Warning: Illegal offset type in <file location>example.php on line 12
Warning: Illegal offset type in <file location>example.php on line 16

Those refer to the two lines containing the reference to "$questions[$question]" specifically.

[Code.........]

I think I'm just beyond my skill level here, because while I can see the warning on [URL] that states "Arrays and objects can not be used as keys. Doing so will result in a warning: Illegal offset type.", I cannot see how what I'm doing is any different than Example #7 on that very page.

View 3 Replies View Related

Changes The Type Of $a From Integer To Object?

Mar 11, 2011

<?php
$a = 3;
echo 'typeof $a is : ' . gettype($a) . "

[code]...

View 6 Replies View Related

Illegal Offset

Mar 8, 2007

I want to pass a class into an array, but I seem to be doing something illegal. here is the details

$characterListing = array($me=>$me->GetIsPlayer(), $him=>$him->GetIsPlayer());
error message: Warning: Illegal offset type in c:InetpubwwwrootMyProjectsSecondOfferinghtmlFns.php on line 133

How can I get around this?

View 5 Replies View Related

Illegal Offset Using Dynamic Variable?

Apr 3, 2011

I dont unserstand why do i get such errors:

Warning: Illegal offset type in
index.php on line 10 USD 1.4141
Warning: Illegal offset type in
index.php on line 10 JPY 118.56

Here's my code:

<?php
$xml = simplexml_load_file("eurofxref-daily.xml");
$array=array();
foreach ($xml->children() as $cubeMain) {

[Code]...

View 1 Replies View Related

Cannot Use Object Of Type * As Array

Apr 14, 2010

I think my webhost recently updated their PHP to version 5 and I now get this nasty error:

Quote: PHP Fatal error: Cannot use object of type users as array in E:**wwwrootplannerlibsite.lib.php on line 102

The line 102 in site.lib.php is

PHP Code:

if ($_SESSION['user']['logged_in']  == true) { 

Wich worked fine. The $_SESSION['user'] is set when logging in by this line:

It seems like $userq is a object now instead of a array. Did they change this in php5? I tried to use

PHP Code:

if ($_SESSION->user->logged_in == true) {

But that didnt work either.

View 13 Replies View Related

Cannot Use Object Of Type StdClass As Array When Trying To Modify A Array?

May 10, 2011

I've just read a simple array from my db that was json_encoded, so i decoded it and tried to change a value at index 0, but i get the following errorcannot use object of type stdClass as array when trying to modify a array

View 2 Replies View Related

Cannot Use Object Of Type StdClass As Array

Feb 28, 2011

I'm leveraging SOAP calls to retrieve an array of values based. What I can't figure out is how to get to the values (eg-name, ssn, etc) once the entire array has been returned. If I try something like: $results[1], I get the error: Cannot use object of type stdClass as array.Code is below.

PHP Code:
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); 

    set_time_limit(0); 
    require_once("./include/nusoap/nusoap.php"); [code].....

View 5 Replies View Related

Cannot Use Object Of Type _Incomplete_Class As Array?

Nov 28, 2009

I am facing the error in my cart basket..Cannot use object of type __PHP_Incomplete_Class as array on line.........

View 1 Replies View Related

Error: Cannot Use Object Of Type StdClass As Array'

Apr 1, 2011

Derp.Getting 'Fatal error: Cannot use object of type stdClass as array'

I dunno what I'm doing wrong here:

foreach ($json->result->items[$key]->attributes->attribute as $attrib => $val)
{
if($json->result->items[$key]->attributes->attribute[$attrib]->name == 'cannot_trade')
{
$notrade=1;
echo 'Item ' . $key . ' is not tradeable' . $br;
}
}........

View 2 Replies View Related

Oop - Passing In An Array Of Type Object To The Constructor?

Mar 28, 2011

When Defining a constructor in a class I initially had something like:

public function __construct(MyClass $class){ ... }

However I wanted to be able to accept an array of MyClasses, how could you define this in your constructor?

View 3 Replies View Related

'Cannot Use Object Of Type StdClass As Array' Using Wordpress

May 30, 2011

I am trying to retrieve the slug for a tag inside a wordpress post, now its possible to get all tag info using

$tag = wp_get_post_tags($post->ID);

More info on this on the Wordpress Docs

By using this you should get data returned like this...

Array
(
[0] => stdClass Object
(
[term_id] => 4

[Code]....

Now what I want is the slug for the first item which should be as follows

$tag[0]['slug']

However by doing so I recieve this php error:

Cannot use object of type stdClass as array

View 1 Replies View Related

Getting Error: Cannot Use Object Of Type Mysqli_result As Array?

Jul 31, 2010

I'm following a php pagination tutorial that uses MYSQL but I use MYSQLI object oriented all around my site. This is causing some errors..

For this part..

$sql = "SELECT COUNT(*) as num FROM categories";
$total_pages = $connection->query($sql) or die(mysqli_error($connection));
$total_pages = $total_pages['num'];

I get *Fatal error: Cannot use object of type mysqli_result as array*.. on the last line

so I switched it to

$sql = "SELECT COUNT(*) as num FROM categories";
$total_pages = $connection->query($sql) or die(mysqli_error($connection));
$row = $total_pages->fetch_assoc();
$total_pages = $row[num];

and now I get Use of undefined constant num - assumed 'num' ..on the last line.

At this point, I'm not sure what else to do.

View 2 Replies View Related

Cannot Use Object Of Type StdClass As Array Error

Dec 12, 2009

I am trying to make my php login check if the user has a verified account or not, I'm doing this by either "0" or "1" in the uses table, 0 meaning its not and 1 meaning it is. My problem is I keep getting the following error: Fatal error: Cannot use object of type stdClass as array in /home/rawradam/public_html/login2.php on line 31

Here is the code to go with it:

if($row['verify'] == "0"){
echo "Your account has not been verified.";
}

I don't know if I'm miles off the ball or if I am doing the right thing, but just getting it mixed up,

View 5 Replies View Related

Json_decode To Array - Fatal Error : Cannot Use Object Of Type?

Mar 2, 2011

I am trying to decode Json into an array but i get the following error.

Fatal error: Cannot use object of type stdClass as array in C:wampwww empasklaila.php on line 6

code <?php
$json_string = 'http://www.domain.com/jsondata.json';
$jsondata = file_get_contents($json_string);
$obj = json_decode($jsondata);
print_r($obj['Result']);
?>

View 2 Replies View Related

Accessing Object Properties Of Type Array Dynamically?

Jan 25, 2011

I am building a Language class for internationalization, and I would like to access the properties dynamically (giving the string name), but I don't know how to do it when dealing with arrays (this is just an example):

class Language {

public static $languages_cache = array();
public $index_header_title;
public $index = array(
"header" => array(

[Code]....

So, outputting members:

echo _('index_header_title', "en"); //works
echo _('index["header"]["title"]', "en"); //does not work

I would need a way for accessing arrays dynamically.. for public and private via __set() function.

View 1 Replies View Related

Fatal Error: Cannot Use Object Of Type PEAR_Error As Array

Sep 21, 2007

im USING PEAR serialize class. when ever i pass an integer value in array this error massages comes out :: Fatal error: Cannot use object of type PEAR_Error as array

i need the integer value for mathematical operations. ive already used typecast, intval, to_number.. etc... it didnt work.

View 6 Replies View Related

IMAP : Fatal Error: Cannot Use Object Of Type StdClass As Array

May 9, 2011

when I create test e-mail or I will forward the specific e-mail, the script works correctly - saves attachment into server disk. now, when I configure to check another mailbox, it gives me error:

Num Messages 11

Fatal error: Cannot use object of type stdClass as array in /test/emailattach/index.php on line 34

index.php:
Code: [Select]<?php
$mbox = imap_open("{mail.server.com:143}", "email@email", "XXX") or die('Cannot connect to mail: ' . imap_last_error());

[Code]....

View 2 Replies View Related

Type Casting An Decoded Json Object To Array, Generate Error While Accessing It?

Mar 27, 2011

I decoded a json string and then Type casted it into any Array and tried to access it later. But it generate Undefined Index Error

Here is my sample code

$json = '{"1":"Active","0":"Inactive"}'; //Yes, it is a valid Json String
$decodedObject = json_decode($json);
$array = (array)$decodedObject;
echo $array['1']; // This generates undefinded Index 1 Error

Here is the display of the array and object

stdClass Object
(
[1] => Active
[0] => Inactive[code]....

View 2 Replies View Related

Warning: Pack() [function.pack]: Type H: Illegal Hex Digit G In /code?

Jan 19, 2011

i am having some problems using pack() in php

$currencypair = "EUR/USD";
$buy_sell = "buy";
$alert_device_token =array("a","a","b");[code]...

Now sometimes i get following warnings running the same code -

Warning: pack() [function.pack]: Type H: illegal hex digit g in /code/FR2BVl

the illegal hex digit keeps varying though.

View 1 Replies View Related

Form, Input Type To Be An INTEGER

Jun 13, 2005

where "XXXX" needs to be an INTEGER instead of "TEXT" anything else.

<form method="post" action="myphpfile.php">
<input type="xxxx" name="quantity">
<input type="submit" name = "submit" value="quantity">

View 3 Replies View Related

Check What Type (integer, String Etc) A Database Field Is

Jul 17, 2005

If i have a datebase field like so:

$username = $row['username']; //after SELECT and mysql_query etc.

how do i check what file type it is? i have tried using is_string to
check it but it returns all fields back as strings, even the ones i
know are integers. i would like something that would tell me the data
tyle (integer, varchar, text etc). are there any other ways or am i
doing this wrong?

View 1 Replies View Related

Adding Results From Query 2 To Query 1 - Cannot Use Object Of Type Mysqli_result As Array

Apr 29, 2011

I make two queries and I'd like to add rows from query 2 to query 1. Also, suppose getResult1() returns no column called "item2"

$result1 = getResult1();
$result2 = getResult2();
foreach ($result2 as $res)

[code]....

There error I get here is on line

$result1[] = $data

and reads

Fatal error: Cannot use object of type mysqli_result as array

I think I get what is happening, but I'm not quite sure how to fix it.The rows are ultimately getting converted to JSON, and I can do that that with an array of arrays.I've fixed the problem by converting $result1 into an array of arrays. I do this using a while loop and a fetch_array() call, but is there a quick way to just convert $result1 into an array of arrays instead of a record set?

View 3 Replies View Related

Error "Cannot Use Object Of Type StdClass As Array"

Dec 30, 2010

I have the following PHP code:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);

[code]...

which works fine for URL #1 (into the variable $URL): [URL] but causes an error "Cannot use object of type stdClass as array" for URL #2: [URL]

View 1 Replies View Related

Datatypes - Convert Object To Integer?

Feb 24, 2009

The value of $total_results = 10 $total_results in an object, according to gettype() I cannot use mathematical operators on $total_results because it's not numeric Tried $total_results = intval($total_results) to convert to an integer, but no luck The notice I get is: Object of class Zend_Gdata_Extension_OpenSearchTotalResults could not be converted to int

How can I convert to an integer?

View 4 Replies View Related

Using Object Paradigm On Atomic Integer Value For Display Purpose?

Jan 13, 2011

I am working on financial values for poker games. All amounts are internally given as cents. Therefore, the type is integer. But, I need to display the amounts in several ways. So far, I work like this (PHP) :

class Amount
{
private value;
public function set($v) ...
public function get() ...
public function add($v) ... // $v is integer

[Code]....


It works like a charm, but since PHP is not able to overload operators, my code is quite "heavy" and I am wondering if I am doing it the wrong way. Finally, is it still "object paradigm" to work like this :

$value1 = 100;
$value2 = 200;
$val = new Amount($value1 + $value2);
echo $val->display1();

The code is liter when doing operations, but I feel wrong creating a new Amount object each time I just want to display a value (and in this case the class name would be AmountDisplayer).

My question : what is the correct POO way to work with integer values ?

View 1 Replies View Related

Socket Server "Undefined Offset" And Wrong Resource Type E?

Apr 25, 2010

This is a continuation of the same script, but I have come upon a new error.If I have a client leave the server, the socket server goes crazy and starts looping extremely rapidly after firing off a series of errors about attempting to close the socket.If another client tries to join after this, then the "Undefined offset" error starts recurring again and again.

#!/usr/local/bin/php -q
<?php
error_reporting(E_ALL);
[code].......

View 1 Replies View Related

Creating Multidimensional Array - Fatal Error: Can't Use String Offset As An Array

Feb 10, 2010

I am working on a project where the left nav will be automatically generated based on an array of menu elements.. Is there something wrong with this?

[code]...

The error I always get is: Fatal error: Cannot use string offset as an array in

View 3 Replies View Related

Array Offset Is Set

Nov 10, 2005

I have a double-dimension arrays I can call the data:

array[0][0] and array[1][1]

The data displays properly, but i keep getting the error: Undefined offset. I can't figure out whats going on.

View 3 Replies View Related

Pdf To Jpg Convertion

Oct 14, 2004

I m trying to convert a pdf file into a jpg image but i did not find any way to do that except using imagemagick

(i read that on a forum but i cant make it work !)

does anybody has a solution or an idea to make that possible ?

i cant imagine that we cant do it because convert a jpg file to a pdf is so easy and generate jpg file with GD too....

View 1 Replies View Related

String Offset As An Array

Jun 29, 2007

PHP Code:

<?php
// Declare variables //
$debug = false;
$url = "http://www.mto.gov.on.ca/english/traveller/conditions/rdclosure.htm";
//$url = "./roadclosed1/rdclosure.htm";
$email_recip = "REMOVED";
#$email_recip = "REMOVED";
#$email_subject = MOVED TO LINE 47
$email_from = "WxServer Roads";
$email_from_addr = "REMOVED";
$message_header = "
====START====
.......

View 3 Replies View Related

Can't Use Sting Offset As An Array?

Mar 4, 2010

I just updated my homeserver to PHP 5.3.1 and I get now the following error when executing my scripts:

Cannot use string offset as an array The variable looks like: $bes[$a[3]][$a[4]][$a[6]], where $bes is a three-dimensional array that holds all information I need during runtime. The $a's can basically hold the information about a location, a day and an hour. So after runtime I have a nice smooth table of all information I need for a place and a time.

So the problem is, that the main variable causes the problem. Replacing it with something new means to rewrite the whole code. And this is as you know awful work and costs quite a few bucks. The old server (online): Apache 2.0.54 / PHP 4.3.10-22 (Debian, I guess) My new home server: Apache 2.2.14 / PHP 5.3.1 (opensuse 11.2) So has anyone experiences with reorganisation of old PHP-4-code? I tried to use intval() to make all possible strings to ints but that doesn't seem to do the trick.

View 3 Replies View Related

Use String Offset As An Array?

Mar 6, 2009

Quote:Cannot use string offset as an array.

PHP Code:class Bar
{
protected $foo;
public function boo($id)

[code]...

View 3 Replies View Related

Cannot Use String Offset As An Array

Jan 10, 2011

I know the problem that I am having is related to the change in PHP5 about strings and arrays, however I do not understand why my script is affected. It seems like I am not trying to add more variables to an array.

// Build View Array
if ($view_result!=false) {
$i=0;
while ($view_row =@ mysql_fetch_array($view_result)){
$i++;

[Code]....

View 2 Replies View Related

Db Timestamp Convertion?

Aug 4, 2010

What is the correct way to convert from mysql timestamp (YYYY-MM-DD HH:MM:SS) to my own chosen format, something like "August 5, 2010"? iow how can I make the mysql timestamp php date() compatible?

View 4 Replies View Related

Convertion Dates

Mar 5, 2007

I want to convert that date('U'); number into a date can i do that

$ut = date('U');
$rt = 1173128934 + 86400;
$tbthere = $rt - $ut;
echo "

$ut";
echo "
<be>$rt";
echo "
<be>$tbthere";

View 11 Replies View Related

Array's - Notice: Undefined Offset: 1

Dec 14, 2006

I've created a query in SQL to return all Sport teams for a specific users.

$get_sport = mysql_query("SELECT sport_name FROM sport, user_sport WHERE sport.sportID=user_sport.sportID") or die(mysql_error());

$get_sport_val = mysql_fetch_array($get_sport);

The relationship between user and sport is a one-to-many relationship, i.e. one user can have many sports. Code:

View 4 Replies View Related

Cannot Use String Offset As An Array Error?

Mar 18, 2011

I'm trying to retrieve tasks from Rembmer the Milk API. I run this code:

$array = json_decode($content, true);
foreach($array['rsp']['tasks']['list']['taskseries'] as $keys=>$val) {
$task = $val['name'];

[code]...

View 1 Replies View Related

Error: Cannot Use String Offset As An Array

Feb 16, 2011

I use multidimensional arrays to store product attributes (well Virtuemart does, to be precise).When I tried to echo the sub-arrays value, if the sub-array did not exist PHP threw:

Fatal error: Cannot use string offset as an array To get around this, I attempted to create a function to check on every array level if it is an actual array, and if it is empty (when trying on the whole thing at once such as: is_array($array['level1']['level2']['level3']), I got the same error if level1 or level2 are not actual arrays).

This is the function ($array contains the array to check, $array_levels is an array containing the names of the sub-arrays, in the order they should apper):

function check_md_array($array,$array_levels){
if(is_array($array)){
$dimension = null; //This will store the dimensions string
foreach($array_levels as $level){
$dimension .= "['" . $level . "']"; //Add the current dimension to the dimensions string
if(!is_array($array/* THE CONTENT OF $dimension SHOULD BE INSERTED HERE*/)){
return false;

[Code]...

How can I take the string contained in $dimensions, and insert it into the code, to be part of the statement?

View 1 Replies View Related

Use String Offset As An Array Error?

Jan 13, 2010

[URL]...

I have print_r()-ed the actual values in $entries(coming from Google Calendar)and they are all fine.

Code:foreach ( $entries as $e ) {
$info = array(); // added to see if pre-declaration
$info = array(

[code]...

View 2 Replies View Related

String Offset As An Array Error?

Mar 1, 2011

I am writing a data scraping script but i am getting fatal error.My code:-

Code: [Select] <?php 
$con = mysql_connect("localhost","root","");
mysql_select_db("cakeshop", $con);
$test = '<for
[code]..

View 10 Replies View Related

Character Encoding - Utf-8 To Gsm 7 Convertion?

Jun 3, 2010

What should I do to convert utf-8 to gsm-7 in PHP.I got this linkhttp://mobiletidings.com/2009/07/06/gsm-7-encoding-gnu-libiconv/ But dont know how to do this in PHP.

View 1 Replies View Related

Language Convertion Script?

Dec 6, 2010

I want to convert my English content to 7 other languages( Chinese, Spanish, Malayalam, Telgu, Tamil, Kannada and Hindi). Is there any script or anything like that to do this?

View 3 Replies View Related

ADVERTISEMENT