Home > Computer Tutorials > Computer Knowledge > What functions can php use to determine data type?

What functions can php use to determine data type?

PHPz
Release: 2024-01-17 12:06:12
forward
1346 people have browsed it

What functions can php use to determine data type?

What are the php data type judgment functions

Enter the ext directory in the PHP source program directory. The source code of each extension module is stored here. Select the module you need, such as the curl module: cd curl

Execute phpize to generate the compiled file, phpize is in the bin directory of the PHP installation directory

/usr/local/php5/bin/phpize

When running, an error may be reported: Cannot find autoconf. Please check your autoconf installation and

the $PHP_AUTOCONF

environment variable is set correctly and then rerun this

script., need to install autoconf:

yum install autoconf (RedHat or CentOS), apt-get install

autoconf(Ubuntu Linux)

/usr/local/php5/bin/php -v

When executing this command, PHP will check whether the configuration file is correct. If there is a configuration error,

An error will be reported here, you can troubleshoot based on the error message!

Is there any function in php that can get the parameter name and parameter type in a method

/**

* Get the dependencies of a function

* @param string|callable $func

* @param array $param The parameters required when calling the method. The formal parameter name is the key value

* @return array Returns the dependencies required for method invocation

*/

function getFucntionParameter($func,$param=[]) {

if(!is_array($param)) {

$param = [$param];

}

$ReflectionFunc = new \ReflectionFunction($func);

$depend = array();

foreach($ReflectionFunc->getParameters() as $value) {

if(isset($param[$value->name])) {

$depend[] = $param[$value->name];

}elseif($value->isDefaultValueAvailable()){

$depend[] = $value->getDefaultValue();

}else{

$tmp = $value->getClass();

if(is_null($tmp)) {

throw new \Exception("Function parameters can not be getClass {$class}");

}

$depend[] = $this->get($tmp->getName());

}

}

return $depend;

}

function test($a,$b=20) {

echo $a,',',$b;

}

$depend = getFucntionParameter('test',['a'=>30,'b'=>40]);

call_user_func_array('test',$depend); // The functions above 30 and 40 are the container methods of the framework I developed.

php provides a very complete reflection mechanism. Not only can you reflect functions, but you can also reflect methods and class constructors.

PHP variable type conversion function settype problem

This function is: set the type of variable, PHP comes with a function, no configuration is required

settype function structure

bool settype (mixed var, string type)

Interpreted as: return value Boolean value, that is, success or failure. Both parameters are required. The front is to set the type of variables. What follows is the type of variable to be set.

The function ends and there is no output. Only a true or false value will be returned. Tell you whether you succeeded or failed.

Let me give you a piece of code to test.

$foo = "5bar"; //Character variable $foo

settype($foo, "integer"); // Set type of $foo to integer

var_dump($foo); //Print variable information, the result is an integer 5

?>

The type of the variable changes directly after use. Your mistake may be that you added too few parameters.

==================

My personal habit is this

$foo = "5bar";

$a = (int)$foo; //Declare the variable type

var_dump($a); //The result is also an integer 5

?>

The above is the detailed content of What functions can php use to determine data type?. For more information, please follow other related articles on the PHP Chinese website!

source:docexcel.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template