PHP 8.3.4 Released!

variant sınıfı

(PHP 4 >= 4.1.0, PHP 5, PHP 7, PHP 8)

Giriş

VARIANT, COM'un PHP zval eşdeğeridir; farklı olası türlerde değer içerebilen bir yapıdır. COM eklentisi tarafından sağlanan variant sınıfı, PHP'den COM'a ve COM'dan PHP'ye bu değerlerin aktarımında daha fazla denetim sahibi olmanızı sağlar.

Sınıf Sözdizimi

class variant {
/* Yöntemler */
public __construct(mixed $değer = null, int $veri_türü = VT_EMPTY, int $kodlama = CP_ACP)
}

variant örnekleri

Örnek 1 - variant örneği

<?php
$v
= new variant(42);
print
"Değişkenin türü: " . variant_get_type($v) . "<br/>";
print
"Değişkenin değeri: " . $v . "<br/>";
?>

Bilginize:

Bir değer döndürülürken veya bir variant özelliği alınıp getirilirken, yalnızca dönüşüm sırasında türler arasında bilgi kaybına neden olmayacak doğrudan bir eşleme olduğunda bir PHP değerine dönüştürülür. Diğer tüm durumlarda sonuç, variant sınıfının nesnesi olarak döndürülür. PHP, tür dönüşüm işleci kullanılarak örtük vaya doğrudan bir dizge olarak basılmak üzere variant'ın bir PHP yerel türüne dönüştürülmesine veya değerlendirilmesine zorlanabilir. Bir dönüştürmeyi zorlamadan veya veri kaybı riskine girmeden variant'lar üzerinde aritmetik işlemler gerçekleştirmeyi sağlayan variant işlevleri de vardır.

Ayrıca bkz: variant_get_type().

İçindekiler

add a note

User Contributed Notes 2 notes

up
20
darren at dcook dot org
16 years ago
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:
com_print_typeinfo($obj);

It lists all functions, variables, their types in a human-readable (well, programmer-readable) format. Lovely!
up
4
richard dot quadling at carval dot co dot uk
21 years ago
With thanks to Harald Radi and Wez Furlong.

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

e.g.

GoTo What:=wdGoToBookmark, Name="BookMarkName"
GoTo(wdGoToBookmark,,,"BookMarkName)

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

Which is ...

<?php
// Some servers may have an auto timeout, so take as long as you want.
set_time_limit(0);

// Show all errors, warnings and notices whilst developing.
error_reporting(E_ALL);

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

// Load the appropriate type library.
com_load_typelib('Word.Application');

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

// Open a new document with bookmarks of YourName and YourAge.
$word->Documents->Open('C:/Unfilled.DOC');

// 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.
$word->Selection->TypeText($_GET['YourName']);

$word->Selection->GoTo(wdGoToBookmark,$empty,$empty,'YourAge');
$word->Selection->TypeText($_GET['YourAge']);

// Save it, close word and finish.
$word->Documents[1]->SaveAs("C:/{$_GET['YourName']}.doc");
$word->Quit();
$word->Release();
$word = null;
print
"Word closed.\n";
?>

The example document is ...

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

and it would be called ...

word.php?YourName=Richard%20Quadling&YourAge=35

Regards,

Richard.
To Top