Chinaunix
标题:
PHP 和 Ruby 的基本常量变量、类的简单书写
[打印本页]
作者:
三里屯摇滚
时间:
2011-12-18 17:27
标题:
PHP 和 Ruby 的基本常量变量、类的简单书写
PHP 和 Ruby 的基本常量变量、类的简单书写
PHP 变量、常量
变量:$var = "1000";
常量:define("ROOT","/tmp");
类常量:const aaa = 10;
类变量:同样还是$xxx;
全局变量: global $xxx; $GLOBALS['xxxx']
Ruby 变量、常量
变量:aa = 10 或者 _a = 10 小写字母或者下划线开头
常量:Ma = 10
实例变量:@hello = 10
类变量:@@t = 20
全局变量:$aa = 10
PHP基本的类实例化
Php代码
<?php
class demo {
function __construct($name) {
$this -> name = $name;
}
function say() {
echo $this -> name;
}
function __destruct() {
}
}
$p = new demo("yang");
$p -> say();
<?php
class demo {
function __construct($name) {
$this -> name = $name;
}
function say() {
echo $this -> name;
}
function __destruct() {
}
}
$p = new demo("yang");
$p -> say();
复制代码
Ruby基本的类实例化
Ruby代码
class Hello
def initialize( name )
@name = name
end
# php function __construct
def hello_rb
puts "hello"+@name
end
复制代码
end
hi = Hello.new("phper.yang")
hi.hello_rb
class Hello
def initialize( name )
@name = name
end
# php function __construct
def hello_rb
puts "hello"+@name
end
复制代码
end
hi = Hello.new("phper.yang")
hi.hello_rb
复制代码
PHP类的简单继承
Php代码
class my {
function say() {
echo "hello ";
}
}
class hhy extends my {
function yang() {
echo "yang";
}
}
$p = new hhy();
$p -> say();
$p -> yang();
class my {
function say() {
echo "hello ";
}
}
class hhy extends my {
function yang() {
echo "yang";
}
}
$p = new hhy();
$p -> say();
$p -> yang();
复制代码
Ruby类的简单继承
Ruby代码
class Hello
def t1
yang = "hello ruby"
puts yang
end
end
复制代码
class Newhello < Hello
def t2
yphp = "hello php"
puts yphp
end
end
p = Newhello.new
p.t1
p.t2
class Hello
def t1
yang = "hello ruby"
puts yang
end
end
class Newhello < Hello
def t2
yphp = "hello php"
puts yphp
end
end
p = Newhello.new
p.t1
p.t2
复制代码
ruby 的类名首字母必须大写
作者:
梦境照进现实
时间:
2011-12-19 11:25
学习了..谢谢分享了
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2