Skip to content

Instantly share code, notes, and snippets.

@tzmfreedom
Last active September 27, 2020 01:34
Show Gist options
  • Save tzmfreedom/fa3f71cc0d11c975e6c0f8b617ce7e3b to your computer and use it in GitHub Desktop.
Save tzmfreedom/fa3f71cc0d11c975e6c0f8b617ce7e3b to your computer and use it in GitHub Desktop.
<?php
require_once 'vendor/autoload.php';
echo $nodefined; // Variable $nodefined might not be defined.
$tmp1 = new NoExist(); // Instantiated class NoExist not found.
$tmp2 = noFunction(); // Function noFunction not found
class Hoge {
public function someMethod(int $someArg): string {
return 1; // Method Hoge::someMethod() should return string but returns int.
// return 1 // Syntax error, unexpected '}', expecting ';' on line 12
}
private function privateMethod() {}
public function noTypeHint($arg) {
// Method Hoge::noTypeHint() has parameter $arg with no typehint specified.
return true; // Method Hoge::noTypeHint() has no return typehint specified.
}
/**
* @param Hoge $var
**/
public function phpdoc1(): void {} // PHPDoc tag @param references unknown parameter: $var
/**
* @param Hoge[] $hoges
**/
public function phpdoc2(array $hoges): void {
echo $hoges[0]; // Parameter #1 (Hoge) of echo cannot be converted to string.
echo $hoges[0]->methodMissing(); // Call to an undefined method Hoge::methodMissing().
}
// Method Hoge::phpdoc3() has parameter $hoges with no value type specified in iterable type array.
public function phpdoc3(array $hoges): void {}
}
$hoge = new Hoge();
echo $hoge->fuga; // Access to an undefined property Hoge::$fuga
echo $hoge->hello(); // Call to an undefined method Hoge::hello().
echo $hoge->someMethod(); // Method Hoge::someMethod() invoked with 0 parameters, 1 required.
echo $hoge->someMethod('123'); // Parameter #1 $someArg of method Hoge::someMethod() expects int, string given.
echo $hoge->privateMethod(); // Call to private method privateMethod() of class Hoge.
echo in_array([], ""); // Parameter #2 $haystack of function in_array expects array, string given
if (false) {
// dead code // If condition is always false.
}
$var = new stdClass();
if ($var instanceof Hoge) {} // Instanceof between stdClass and Hoge will always evaluate to false.
@tzmfreedom
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment