Specify Data Type from WMI

I am pulling ChassisTypes in W32_SystemEnclosure from WMI with PHP. ChassisTypes is an enumerated, interger-valued array that indicates what type of chassis the computer is (Desktop, Notebook, Laptopt, etc). When echoing or printing the type, I receive the following message:

Recoverable fatal error : Object of class variant could not be converted to string

To work with WMI, you must add extension=php_com_dotnet to php.ini

<?php
$WbemLocator = new COM ("WbemScripting.SWbemLocator");

$WbemServices = $WbemLocator->ConnectServer('localhost', 'root\\cimv2');

$enclosure = $WbemServices->execQuery("Select * from Win32_SystemEnclosure");

foreach($enclosure AS $key){
	$type = $key->ChassisTypes;
	
	echo $type;
}
?>

I have tried to settype() the output but I receive the same message. Is there a way to display the results of the ChassisTypes?

You could do a var_dump to determine the type, or everything being held in the object itself.

Thanks for the response.
VAR_DUMP returns

object(variant)#6 (0) { }

That 6 is what I’m needing to return, but I’m not sure how.

I had to use a nested foreach. Maybe there’s a better way to write this?

foreach($enclosure AS $key){
	$type = $key->ChassisTypes;
	
	foreach($type AS $t){
		
		echo $t; //outputs 6 (Mini Tower)
	}
	
}
Sponsor our Newsletter | Privacy Policy | Terms of Service