echo sprintf("%s", "Hello PHPUG!");
function greet(string $name) {
echo sprintf(
"Hello %s",
$name
);
}
$name = "PHPUG";
greet($name);
class Person {
public $age = null;
}
$tim = new Person();
$tim->age = 25;
echo sprintf(
"Tim is %d years old",
$tim->age
);
class Person {
public $age;
private function __construct(int $age) {
$this->age = $age;
}
public static function newWithAge(int $age) : Person {
return new static($age);
}
}
$tim = Person::newWithAge(25);
echo sprintf("Tim is %d years old", $tim->age);
function greet(string $name) {
echo "Hello ". $name . "\n";
}
$name = "PHPUG";
greet($name);
greet($name);
// Frag den Ram nach Platz für ne Zval
//
// typedef union _zvalue_value {
// long lval; /* long value */
// double dval; /* double value */
// struct {
// char *val;
// int len; /* this will always be set for strings */
// } str; /* string (always has length) */
// HashTable *ht; /* an array */
// zend_object_value obj; /* stores an object store handle, and handlers */
// } zvalue_value;
//
// registriere die variable im GC
$a = "Foo";
// und prüf hin und wieder und am ende, ob die variable noch gebraucht wird
# sudo dtrace -n 'pid$target::malloc:entry' -c "php malloc.php"
function foo() {
return "fooooo";
}
echo "------------------------\n";
sleep(2);
while(true) {
$a = foo();
sleep(0.5);
}
$ phpbrew install 5.4.0 +default $ phpbrew use 5.4.22
$ curl https://sh.rustup.rs -sSf | sh $ rustup default nightly
composer.json / composer.lock
Cargo.toml / Cargo.lock
$ cargo new --bin hellophpug $ cargo run
if (
file_exists($mod.'.rs') &&
file_exists($mod.'/mod.rs')
) {
throw new \Exception(
'[file].rs or [file]/mod.rs?'
);
} else if (file_exists($mod.'.rs')) {
include $mod.'.rs';
} else if (file_exists($mod.'.rs')) {
include $mod.'/mod.rs';
}
$ cargo new --bin webfoo
[dependencies]
nickel = "*"
#[macro_use] extern crate nickel;
use nickel::{Nickel, HttpRouter};
fn main() {
let mut server = Nickel::new();
server.get("/", middleware!(
let a = "Hello World";
a
));
server.get("/bar", middleware!("Bar"));
server.listen("127.0.0.1:6767");
}
$ cargo run
class Person {
private $age;
function __construct($age) {
$this->age = $age;
}
function getAge() {
return $this->age;
}
}
echo sprintf(
"Tim is %d years old",
(new Person(25))->getAge()
);
$numbers = [1, 2, 3, 4, 5, 6, 10, 100];
$result =
array_values(array_map(
function($a) { return $a * 2; },
array_filter(
array_filter($numbers, function($a) { return $a > 4; }),
function($a) { return $a < 100; }
)
));
$result[] = 10;
$result[] = 11;
var_dump($numbers);
class Option<T> {
private T $value;
public function __construct(T $value) {
$this->value = $value;
}
public function unwrap() {
if ($this->value === null) { die('yolo'); }
return $this->value;
}
}
echo (new Option<String>("hello"))->unwrap();
echo (new Option<String>(null))->unwrap();
while (($line = fgets(STDIN)) !== false) {
$matches = [];
preg_match('/\d+$/', $line, $matches);
if (!isset($matches[0])) {
continue;
}
$url_number = $matches[0];
echo $url_number."\t".'1'."\n";
}
$lastNumber = null;
$lastCount = 0;
while (($line = fgets(STDIN)) !== false) {
list($number, $count) = explode("\t", $line);
if ($lastNumber === null) {
$lastNumber = $number;
}
if ($lastNumber === $number) {
$lastCount++;
continue;
}
echo $lastNumber."\t".$lastCount."\n";
$lastCount = 1;
$lastNumber = $number;
}
if ($lastCount && $lastNumber) {
echo $lastNumber."\t".$lastCount."\n";
}