`
sillycat
  • 浏览: 2539331 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

PHP(4)Types - Variables

    博客分类:
  • PHP
 
阅读更多
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
分享到:
评论

相关推荐

    php.ini-development

    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 ...

    vim数据库插件dbext_420

    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 ...

    PHP函数import_request_variables()用法分析_.docx

    `import_request_variables()`是PHP中的一个函数,它在旧版本的PHP中被用来在`register_globals`设置关闭的情况下,将GET、POST和Cookie变量导入到全局作用域中。由于安全问题,这个函数在PHP 5.3.0版本后被废弃,并...

    PHP-manual外文文献

    - **Types**(类型):描述PHP支持的数据类型,例如整型、字符串、数组等。 - **Variables**(变量):解释变量的声明和使用方法,包括变量的作用域和生命周期。 - **Constants**(常量):介绍常量的定义以及...

    Mastering PHP 7

    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, ...

    Library to build PHP extensions with C++

    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 ...

    Learning PHP(O'Reilly,2016)

    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 ...

    Beginning PHP 5.3

    - **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. #...

    Learning PHP : A Gentle Introduction to the Web's Most Popular Language [2016]

    • 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 ...

    php英文开发文档

    •Types •Variables •Constants •Expressions •Operators •Control Structures •Functions •Classes and Objects •Namespaces •Exceptions •Generators •References Explained •Predefined Variables •...

    PHP and MYSQL Bilbe [英文原版]

    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 ...

    Zend PHP 5 Certification Study Guide(3ed,2015)

    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...

    PHP函数import_request_variables()用法分析

    4. **脚本维护**:对于维护旧有使用`import_request_variables()`的脚本时,要特别注意检查是否存在变量名冲突和安全风险。 总结来说,`import_request_variables()`函数虽然方便,但因其安全风险和维护问题,在新...

    psl:PHP标准库-适用于PHP程序员的一组现代,一致,集中,类型正确的API

    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 \...

    X-CART GOLD v3.4.9

    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 ...

    OCI8-2.1.8

    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 ...

    php代码-1123123123

    - **变量(Variables)**:PHP使用 `$` 符号来声明变量,例如 `$name = 'John';` - **数据类型(Data Types)**:包括字符串(String)、整型(Integer)、浮点型(Float)、布尔型(Boolean)、数组(Array)、对象...

Global site tag (gtag.js) - Google Analytics