定义:

<?php
class foo-----定义类
{
    function do_foo()---类的方法
    {
        echo "Doing foo."; 
    }
}

$bar = new foo;----实例化类
$bar->do_foo();---调用类的方法
?>

当函数是有条件被定义时,必须在调用函数之前定义。

foo()------------出错,函数未定义

if ($condition) {
  function foo()
  {
    echo "I don't exist until program execution reaches me.\n";
  }
}

foo()------------如果$condition为true则可以调用,如果是false则不可以调用?(我猜的)

-------------------------------------------------------------------------------------------------------------------

function foo()
{
  function bar()
  {
    echo "I don't exist until foo() is called.\n";
  }
}

/* 现在还不能调用bar()函数,因为它还不存在 */

foo();

/* 现在可以调用bar()函数了,因为foo()函数
   的执行使得bar()函数变为已定义的函数 */

bar();

----------------------------------------

返回函数引用

<?php
function &returns_reference()
{
    return $someref;
}

$newref =& returns_reference();
?>

可变函数

function foo() {
    echo "In foo()<br />\n";
}

function bar($arg = '') {
    echo "In bar(); argument was '$arg'.<br />\n";
}

// 使用 echo 的包装函数
function echoit($string)
{
    echo $string;
}

$func = 'foo';
$func();        // This calls foo()

$func = 'bar';
$func('test');  // This calls bar()

$func = 'echoit';
$func('test');  // This calls echoit()

调用静态方法

<?php
class Foo
{
    static $variable = 'static property';
    static function Variable()
    {
        echo 'Method Variable called';
    }
}

echo Foo::$variable; // This prints 'static property'. It does need a $variable in this scope.
$variable = "Variable";//这个应该可以改变静态variable的值(我猜)
Foo::$variable();  // This calls $foo->Variable() reading $variable in this scope.

?>

继承父类变量

$message = 'hello';

// Inherit by-reference
$example = function () use (&$message) {
    var_dump($message);
};
echo $example();

最新文章

  1. Node.js的Formidable模块的使用
  2. 项目中遇到的Integer问题--转
  3. zookeeper系列之通信模型(转)
  4. PHP 如何读取一个1G的文件大小
  5. vimtutor
  6. Bleed Brake Master Cylinder with Intelligent Tester IT2
  7. java 保留小数点后N位数(若干位),几种实现的方式总结
  8. iOS RGB颜色封装
  9. maven 配置安装
  10. python 操作Memcached
  11. (摘录)Java 详解 JVM 工作原理和流程
  12. yii2 用 bootstrap 给元素添加背景色
  13. unable to load http://docbook.sourceforge.net/release/xsl/current/html/docbook.xsl
  14. postgres(pgAdmin) 客户端保存密码
  15. idea常用快捷键及自定义快捷键汇总
  16. ss server端配置
  17. drupal7 获取profile2模块自定义字段的值
  18. javascript利用jquery-1.7.1来判断是否是谷歌Chrome浏览器
  19. JavaWeb总结(三)
  20. 【maven】Maven打包后为何文件大小改变了

热门文章

  1. CentOS6.3编译安装Memcached的PHP客户端memcache
  2. 第2月第25天 BlocksKit
  3. Alpha版本十天冲刺——Day 10
  4. 从零开始学jQuery插件开发
  5. php时区问题
  6. xmind portable
  7. 无阻塞加载js,防止因js加载不了影响页面显示
  8. Effective Python2 读书笔记2
  9. jquery检测浏览器类型
  10. oracle中根据当前记录查询前一条和后一条记录