473,544 Members | 1,870 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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($folderlis tfile);

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

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

// 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(SimpleXM LElement)#5 (1) { [0]= string(1) "0" }
UNKNOWN:0
mainid = 0 : id = 1003
object(SimpleXM LElement)#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($detail s->mainid) displays SimpleXMLElemen t 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
Thanks.

Manish

Jul 27 '06 #1
1 13031

Got solved the problem by casting the variable.

(string) $variable;

Manish wrote:
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($folderlis tfile);

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

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

// 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(SimpleXM LElement)#5 (1) { [0]= string(1) "0" }
UNKNOWN:0
mainid = 0 : id = 1003
object(SimpleXM LElement)#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($detail s->mainid) displays SimpleXMLElemen t 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
Thanks.

Manish
Aug 7 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
4346
by: __PPS__ | last post by:
Actually what I mean is that - if I have some memory buffer, lets say char a; and then I do like this: DWORD num = 0x1234; *(DWORD*)a = num; (1) *(DWORD*)(a+1) = num; (2) either (1) or (2) will assign dword value to not dword aligned address. The question is - will this code be fatal on some systems??
14
42360
by: deko | last post by:
Is there a way to check user input for illegal characters? For example, a user enters something into a text box and clicks OK. At that point I'd like to run code such as this: illegal = Array(\, /, :, *, ?, ", <, >, |) If Me.TextBox Contains illegal Then MsgBox "You entered illegal characters. Please try again." Me.TextBox = Null
11
3448
by: Bradford Chamberlain | last post by:
I work a lot with multidimensional arrays of dynamic size in C, implementing them using a single-dimensional C array and the appropriate multipliers and offsets to index into it appropriately. I tend to iterate over subsets of these arrays by walking a pointer and an offset per dimension across their dimensions. I've found that this tends...
29
5421
by: shmartonak | last post by:
For maximum portability what should the type of an array index be? Can any integer type be used safely? Or should I only use an unsigned type? Or what? If I'm using pointers to access array elements as *(mptr+k) where I've declared MYTYPE *mptr; what should be the type of 'k'? Should it be ptrdiff_t?
6
5165
by: Charles Law | last post by:
I want to do something like this: obj = CType(value, Value.Type) Well, not exactly, but I think that captures the essence. I realise it won't work as I have written it, and it looks a bit like a nebulous statement, but I am looking for a generic way to convert a variable of unknown type to its actual type. Perhaps a better example...
7
4212
by: Ben R. | last post by:
How does automatic type casting happen in vb.net? I notice that databinder.eval "uses reflectoin" to find out the type it's dealing with. Does vb.net do the same thing behind the scenes when an invisible cast is made? Is there any reason why one would use databinder.eval while in VB.NET? I can see why one might use it in C# so as to avoid...
134
8932
by: jacob navia | last post by:
Hi Suppose you have somewhere #define BOOL int and somewhere else typedef BOOL int;
4
6884
by: Vlad | last post by:
I am having problems using the file.create method within a function that is called when looping through an array of filepaths. If I call my function with a hardcoded file path --C:\Temp.txt the function creates the file as expected. When I loop through my array I get the error - "ArgumentException was unhandled - Illegal characters in...
1
4491
by: remya1000 | last post by:
i'm using VB.net 2003 application program. i'm trying to convert a VB6 program to VB.NET. The VB6 code i'm trying to convert is shown below. declared g_Share() array in module and trying to add values to it inside form. VB6 (Code inside Module) 'Global type array to hold printer info. Public Type OShare PrinterName As String
0
7370
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7617
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7779
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7387
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7714
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5305
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4924
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3424
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
674
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.