Illegal Offset Type For Array. Object To Integer Convertion

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?

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?

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"

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?

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

[code]...

View 6 Replies View Related

Illegal Offset

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?

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

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?

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

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?

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'

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?

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

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?

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

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?

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?

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

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

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?

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?

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

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

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

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"

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?

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?

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?

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

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

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







Copyrights 2005-15 www.BigResource.com, All rights reserved