简体   繁体   中英

Cast variable in Zend 2

This may be a stupid question, but I need to know how to cast a variable in zf2.

$var = (string) $id ;

How ca I do it with this kind of type :

\MediaLayer\Argument\SelectMediaArguments

This doesn't work:

$arg = (\MediaLayer\Argument\SelectMediaArguments) $var

There is no need to type cast in php.

i could be wrong but ia, guesting that you want you IDE to recognize the $var az the selected class , in that case you need to use phpdoc block :

/* @var $var \MediaLayer\Argument\SelectMediaArguments */
$var = X;

if this is not what you want please be more clear because there is not object casting in php

also Type casting for user defined objects

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM