PHP Doku:: VARIANT Klasse - class.variant.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzWindowsbasierte ErweiterungenCOM and .Net (Windows)COM FunktionenVARIANT

Ein Service von Reinhard Neidl - Webprogrammierung.

COM Funktionen




(PHP 4 >= 4.1.0, PHP 5)


$vVar = new VARIANT($var)


Ein einfacher Container, um Variablen in VARIANT Strukturen zu verpacken.


string VARIANT::VARIANT ([ mixed $value [, int $type [, int $codepage ]]] )

VARIANT Klassen-Konstruktor. Parameter:

Anfangswert. Ist er nicht angegeben, wird ein VT_EMPTY Objekt erzeugt.
spezifiziert den Typ vom Inhalt des VARIANT Objektes. Mögliche Werte sind VT_UI1, VT_UI2, VT_UI4, VT_I1, VT_I2, VT_I4, VT_R4, VT_R8, VT_INT, VT_UINT, VT_BOOL, VT_ERROR, VT_CY, VT_DATE, VT_BSTR, VT_DECIMAL, VT_UNKNOWN, VT_DISPATCH und VT_VARIANT. Diese Werte sind wechselseitig exklusiv, können aber mit VT_BYREF vereinigt werden, um zu spezifizieren, dass es sich um einen Wert handelt. Wird er weggelassen, wird der Typ von value verwendet. Konsultieren Sie bitte die MSDN Library für weitere Informationen.
gibt die Codepage an, welche zur Konvertierung der PHP-Strings in Unicode-Strings und umgekehrt verwendet wird. Mögliche Werte sind CP_ACP, CP_MACCP, CP_OEMCP, CP_SYMBOL, CP_THREAD_ACP, CP_UTF7 und CP_UTF8.

4 BenutzerBeiträge:
- Beiträge aktualisieren...
darren at dcook dot org
17.07.2007 14:59
If you are frustrated that print_r($obj) (where $obj is something returned from a call to a function on a COM object) does not return anything helpful, and that variant_get_type($obj) just returns a number, the function you are actually after is:

It lists all functions, variables, their types in a human-readable (well, programmer-readable) format. Lovely!
mark dot pearson at capita dot co dot uk
29.10.2003 20:51
Running PHP 4.3.2 on Windows 2000 I had to use the following expression to create an empty Variant:

= new Variant(null);
$empty->type //     ==>   1


= new Variant();
$empty->type //     ==>   0

The two expressions return different Variant type values!
richard dot quadling at carval dot co dot uk
26.02.2003 14:50
With thanks to Harald Radi and Wez Furlong.

Some VBA functions have optional parameters. Sometimes the parameters you want to pass are not consecutive.


GoTo What:=wdGoToBookmark, Name="BookMarkName"

In PHP, the "blank" parameters need to be empty.

Which is ...

// Some servers may have an auto timeout, so take as long as you want.

// Show all errors, warnings and notices whilst developing.

// Used as a placeholder in certain COM functions where no parameter is required.
$empty = new VARIANT();

// Load the appropriate type library.

// Create an object to use.
$word = new COM('word.application') or die('Unable to load Word');
"Loaded Word, version {$word->Version}\n";

// Open a new document with bookmarks of YourName and YourAge.

// Fill in the information from the form.
$word->Selection->GoTo(wdGoToBookmark,$empty,$empty,'YourName'); // Note use of wdGoToBookmark, from the typelibrary and the use of $empty.


// Save it, close word and finish.
$word = null;
"Word closed.\n";

The example document is ...

Hello [Bookmark of YourName], you are [Bookmark of YourAge] years old.

and it would be called ...



alain at samoun dot com
2.09.2001 22:37
# I think that we need some examples of this thing:
# Lets define a real variant:
$varREAL=  new Variant("9.34 is a real number",VT_R8);
"Value:". $varREAL->value; # Will print 9.34
# Now an integer
$varINT=  new Variant("9.34 Printed as an integer",VT_INT);
"Value:". $varINT->value; # Will print 9
# Now a string
$varSTR=  new Variant("9.34 Printed as a string",VT_BSTR);
"Value:". $varSTR->value; # Will 9.34 Printed as a string

PHP Powered Diese Seite bei
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)