PHP(4)Types - Variables
1. Types
Previous Types, Booleans, Integers, Floating point numbers, Strings, Arrays
1.1. Objects
$bar = new Foo; new to create the object based from class
$bar->do_foo(); ->call function and method
Converting to object
$obj = (object)’hey’;
echo $obj->scalar; // ‘hey'
1.2. Resources
Resource variables hold special handlers to opened files, database connections, image canvas areas.
PHP 4’s Zend Engine, a resource with no more references to it is detected automatically and it is freed by the garbage collector.
1.3. NULL
1.4. Callbacks
//call back function
function my_callback_function(){
echo “hello”;
}
// callback method from class
class MyClass{
static function myCallbackMethod(){
…snip...
}
}
//Callback Type 1: Simple Callback
call_user_func(‘my_callback_function’);
//Callback Type 2: Static class method call
call_user_func(array(‘MyClass’, ‘myCallbackMethod’));
//Callback Type 3: Object method call
call_user_func(array($obj, ‘myCallbackMethod’));
//Callback Type 4: Static class method call
call_user_func(‘MyClass::myCallbackMethod’);
Closure
$double = function($a){
return $a * 2;
};
$numbers = range(1, 5);
$new_numbers = array_map($double, $numbers); //2, 4, 6, 8, 10
1.5. Type Juggling
PHP does not require explicit type definition in variable declaration.
$foo = “0”; //string
$foo = $foo + 2; // integer, 2
Type Casting
$foo = 10;
$bar = (boolean) $foo; // $bar is a boolean
2. Variables
References:
http://sillycat.iteye.com/blog/1543227
http://sillycat.iteye.com/blog/1638638
http://sillycat.iteye.com/blog/2066063
http://symfony.com/doc/current/book/service_container.html
http://www.php.net//manual/en/language.oop5.php
http://www.php.net/manual/en/language.variables.php
分享到:
相关推荐
Directives are variables used to configure PHP or PHP extensions. ; There is no name validation. If PHP can't find an expected ; directive because it is not set or is mistyped, a default value will ...
3.2 Script Variables |dbext-configure-variables| 3.3 Database Specific Options |dbext-configure-options| 3.4 DB2 Modes |dbext-configure-db2| 4. Mappings and commands |dbext-mappings| 5. Adding ...
`import_request_variables()`是PHP中的一个函数,它在旧版本的PHP中被用来在`register_globals`设置关闭的情况下,将GET、POST和Cookie变量导入到全局作用域中。由于安全问题,这个函数在PHP 5.3.0版本后被废弃,并...
- **Types**(类型):描述PHP支持的数据类型,例如整型、字符串、数组等。 - **Variables**(变量):解释变量的声明和使用方法,包括变量的作用域和生命周期。 - **Constants**(常量):介绍常量的定义以及...
This book is for intermediate level developers who want to become a master of PHP. Basic knowledge of PHP is required across areas such as basic syntax, types, variables, constants, expressions, ...
Type conversion between native C/C++ types and PHP variables is handled by PHP-CPP, using features from the C++11 language. It does not matter if your functions accept strings, integers, booleans or ...
Understand data types, variables, logic, looping, and other language basics Explore how to use arrays, functions, and objects Build and validate web forms Work with databases and session management ...
- **Variables and Data Types:** Introduction to PHP variables and data types (strings, integers, arrays, etc.). - **Simple Operations:** Basic arithmetic and string manipulation examples using PHP. #...
• Understand data types, variables, logic, looping, and other language basics • Explore how to use arrays, functions, and objects • Build and validate web forms • Work with databases and session ...
•Types •Variables •Constants •Expressions •Operators •Control Structures •Functions •Classes and Objects •Namespaces •Exceptions •Generators •References Explained •Predefined Variables •...
Chapter 4: Adding PHP to HTML 53 Chapter 5: Syntax and Variables 61 Chapter 6: Control and Functions 83 Chapter 7: Passing Information between Pages119 Chapter 8: Strings 137 Chapter 9: Arrays and ...
The book is updated to provide a discussion of modern best practices when dealing with PHP variables and types, arrays, strings, databases, object-oriented programming and patterns, web security, XML...
4. **脚本维护**:对于维护旧有使用`import_request_variables()`的脚本时,要特别注意检查是否存在变量名冲突和安全风险。 总结来说,`import_request_variables()`函数虽然方便,但因其安全风险和维护问题,在新...
declare (strict_types= 1 ); use Psl \ Arr ; use Psl \ Str ; /** * @psalm-param iterable<?int> $codes */ function foo ( iterable $ codes ): string { /** @var list<int> $codes */ $ codes = Arr \...
4. Smarty configuration files are located in ./configs directory. 5. Templates directory: a) Common templates are located in ./skin1 and ./skin1/main directories. b) Customer related templates ...
Basic features include transaction control, binding of PHP variables to Oracle placeholders, and support for large object (LOB) types and collections. Oracle's scalability features such as Database ...
- **变量(Variables)**:PHP使用 `$` 符号来声明变量,例如 `$name = 'John';` - **数据类型(Data Types)**:包括字符串(String)、整型(Integer)、浮点型(Float)、布尔型(Boolean)、数组(Array)、对象...