示例#1
0
 /**
  * This test function contains a code which will
  * create a php warning to happen. This eample show 
  * that in phpunit it will treated as an exception and 
  * it could be catched by 'expectedException' tag and 
  * exception name would be 'PHPUnit_Framework_Error'
  * 
  * @expectedException PHPUnit_Framework_Error
  */
 public function testPhpError()
 {
     $foo_obj = new Foo();
     # Line below will throw an exception here only
     $foo_obj->bar();
     # Code execution will never reach this point
     $this->assertTrue(true);
 }
示例#2
0
function test_dynamic_new()
{
    $f = new Foo();
    $f->bar();
    $k = "Foo";
    $g = new $k();
    $g->bar();
}
function testChainedPropertyAssignmentExpressionHasExpectedEndLine()
{
    Foo::bar(__FUNCTION__)->baz(__FILE__)->value = 'FOOBAR';
}
示例#4
0
<?php

require 'EventCallableObject.php';
EventCallableObject::pushDirectory('.');
$foo = new Foo();
echo $foo->bar(1, 2, 3);
 public function testRuleNotAppliesToDynamicMethodCall()
 {
     $foo = new Foo();
     $foo->bar();
 }
<?php

class Foo
{
    public static function bar()
    {
        echo "Hello";
    }
}
// Instance level
$f = new Foo();
$f::bar();
// Class level
Foo::bar();
<?php

class Foo
{
    public function __call($method, $args)
    {
        if (isset($this->{$method})) {
            $func = $this->{$method};
            $func($args);
        }
    }
}
$foo = new Foo();
$foo->bar = function () {
    echo "Hello, this function is added at runtime";
};
$foo->bar();
示例#8
0
文件: if.php 项目: badlamer/hhvm
<?php

class Foo
{
    public static function bar($x)
    {
        if ($x == 1) {
            echo "hi";
        }
    }
}
Foo::bar(1);
Foo::bar(2);
示例#9
0
<?php

class Foo
{
    private $test;
    public function __construct($test)
    {
        $this->test = $test;
    }
    public function bar()
    {
        return strrev($this->test);
    }
}
$foo = new Foo('Hello world');
return $foo->bar();
示例#10
0
<?php

namespace HHVM\UserDocumentation\Inconsistencies\Intro\Examples\LVP;

class Foo
{
    function bar($baz)
    {
        $baz = 'herpderp';
        // Always outputs array('herpderp')
        var_dump(func_get_args());
    }
}
$f = new Foo();
$f->bar('blah');
示例#11
0
<?php

class Foo
{
    public $x = 0;
    function bar()
    {
        return function () {
            return $this->x;
        };
    }
}
$foo = new Foo();
$qux = $foo->bar();
$foobar = new Foo();
$foobar->x = 3;
var_dump($qux());
var_dump($qux->call($foo));
// Try on an object other than the one already bound
var_dump($qux->call($foobar));
// Pass a non-object as the parameter for binding the closure to.
// Will get a warning
var_dump($qux->call(4));
var_dump($qux->call(null));
$bar = function () {
    return $this->x;
};
$elePHPant = new StdClass();
$elePHPant->x = 7;
// Try on a StdClass
var_dump($bar->call($elePHPant));
示例#12
0
<?php

class Foo
{
    public static function bar($x)
    {
        if ($x == 1) {
            echo "hi";
        } else {
            if ($x == 2) {
                echo "hello";
            } else {
                echo "uhhh";
            }
        }
    }
}
Foo::bar(1);
Foo::bar(2);
Foo::bar(3);
function testArgumentsContainsPropertyPostfixExpression()
{
    Foo::bar(Bar::$baz);
}
示例#14
0
<?php

class Alliteration
{
    public $firstAllit = "cast vicariously as both victim and villain";
    public $clause = array('part1' => 'no mere veneer of vanity');
    public $nested = array(array("is a vestige of the", "vox populi", "now vacant"));
}
class Foo
{
    public function bar($bag_of_stuff)
    {
        echo 'some
    embedded
    newlines';
        echo "\n";
        echo 'Arnold once said: "I\'ll be back"';
        echo "\n";
        $v = "Voila! ";
        $all = new Alliteration();
        echo "{$v} In view humble vaudevillian veteran" . "{$all->firstAllit} {$bag_of_stuff['0']}.\n";
        echo "This visage, {$all->clause['part1']}, " . "{$all->nested[0][0]} \"{$all->nested[0][1]}\"" . " {$all->nested[0][2]}\n";
    }
}
$f = new Foo();
$f->bar(array("by the vicissitudes of fate"));
示例#15
0
<?php

class Foo
{
    var $bar = "bar";
    function bar($what)
    {
        echo "I'm a ", $what, "!\n";
    }
}
$foo = new Foo();
echo $foo->bar, "\n";
$foo->bar("function");
$v8 = new V8Js();
$v8->foo = new Foo();
$v8->executeString('print(PHP.foo.$bar, "\\n");');
$v8->executeString('PHP.foo.__call("bar", ["function"])');
// // Hello, v8
// class Foo {
//     var $bar = null;
// }
//
// $v8 = new V8Js();
// $v8->foo = new Foo;
// $v8->executeString('print( "bar" in PHP.foo ? "yes" : "no" );');
示例#16
0
<?php

class Foo
{
    public function bar($n)
    {
        return $n + 1;
    }
}
class Hooking
{
    public function __call($name, $args)
    {
        echo "Before {$name}!\n";
        $r = call_user_func_array([$this, "_hook_{$name}"], $args);
        echo "After {$name}!\n";
        return $r;
    }
    public static function hook($name)
    {
        runkit_method_rename(get_called_class(), $name, "_hook_{$name}");
    }
}
runkit_class_adopt('Foo', 'Hooking');
Foo::hook('bar');
$foo = new Foo();
echo $foo->bar(10);
echo "\n";
示例#17
0
<?php

class Foo
{
    public $bar = 'propiedad';
    public function bar()
    {
        return 'método';
    }
}
$obj = new Foo();
echo $obj->bar, PHP_EOL, $obj->bar(), PHP_EOL;
<?php

class Foo
{
    public static function __callStatic($name, $args)
    {
        return $name . ' called statically';
    }
}
echo Foo::bar();
// bar called statically
示例#19
0
<?php

require_once $GLOBALS["HACKLIB_ROOT"];
class Foo
{
    public function bar()
    {
        (yield 5);
        return;
    }
    public static function baz()
    {
        if (false) {
            (yield false);
        }
        return;
    }
}
foreach (Foo::baz() as $v) {
    echo $v . "\n";
}
echo "break\n";
$f = new Foo();
foreach ($f->bar() as $v) {
    echo $v . "\n";
}
示例#20
0
 public function testDummy()
 {
     $dependency = $this->prophesize(\Foo\DependencyInterface::class);
     $foo = new Foo($dependency->reveal());
     $this->assertTrue($foo->bar());
 }
function foo()
{
    Foo::bar();
    Foo::bar();
}
示例#22
0
文件: test.php 项目: jpchristie/Scisr
<?php

/**
 * A simple test class
 */
class Foo
{
    function bar()
    {
    }
}
$f = new Foo();
$b = $f->bar();
示例#23
0
<?php

class Foo
{
    public function bar()
    {
    }
}
// new Foo()->bar()
$f = new Foo();
$f->bar();
 function testSuppressionControl()
 {
     // Turning off suppression before execution
     $chain = new ErrorControlChainTest_Chain();
     $chain->setSuppression(false);
     list($out, $code) = $chain->then(function ($chain) {
         Foo::bar();
         // Non-existant class causes fatal error
     })->executeInSubprocess(true);
     $this->assertContains('Fatal error', $out);
     $this->assertContains('Foo', $out);
     // Turning off suppression during execution
     $chain = new ErrorControlChainTest_Chain();
     list($out, $code) = $chain->then(function ($chain) {
         $chain->setSuppression(false);
         Foo::bar();
         // Non-existent class causes fatal error
     })->executeInSubprocess(true);
     $this->assertContains('Fatal error', $out);
     $this->assertContains('Foo', $out);
 }
示例#25
0
<?php

class Foo
{
    var $bar = array();
    static function bar()
    {
        static $instance = null;
        $instance = new Foo();
        return $instance->bar;
    }
}
extract(Foo::bar());
echo "ok\n";
示例#26
0
<?

class Foo
{
  protected $name = 'foo';

  public function bar($m)
  {
    var_dump($this->name);
    $f = function() {
      var_dump($this);
    };
    $f();
    $m();
  }
}

$foo = new Foo;

$foo->bar(function() { var_dump($this); });

示例#27
0
文件: 2085.php 项目: badlamer/hhvm
<?php

trait Too
{
    function bar()
    {
        $abc = 123;
        $a = function ($x) use($abc) {
            $n = func_num_args();
            $args = func_get_args();
            var_dump($n, $args);
        };
        return $a;
    }
    function baz($obj)
    {
        $abc = 456;
        $obj(789);
    }
}
class Foo
{
    use Too;
}
$a = Foo::bar();
Foo::baz($a);
示例#28
0
文件: switch.php 项目: badlamer/hhvm
                break;
            case "common_1":
            case "common_2":
                echo "in common case";
                break;
            case "fallthrough":
                echo "will fall through";
                // FALLTHROUGH
            // FALLTHROUGH
            case "dummy":
                echo "dummy case";
                break;
            default:
                echo "I guess this is the end, my friend";
        }
        echo "\n";
        $y = true;
        $z = 41;
        switch (true) {
            case foo($str):
                echo "helloooo";
                break;
            case $y && $z + 1 == 42:
                echo "nevermind";
                break;
        }
        echo "\n";
    }
}
Foo::bar("specific");
示例#29
0
<?php

/**
 * Another file used for testing
 */
require_once "newfolder/subdir/things.php";
$b = Foo::bar();
示例#30
0
<?php

include __DIR__ . "/../vendor/autoload.php";
use G\IDisposable;
class Bar implements IDisposable
{
    public function hello($name)
    {
        return "Hello {$name}";
    }
    public function dispose()
    {
        echo "Disponse Bar";
    }
}
class Foo
{
    public function bar()
    {
        using(new Bar(), function (Bar $bar) {
            $bar->hello("Gonzalo");
        });
    }
}
$foo = new Foo();
echo $foo->bar();