Skip to content

Instantly share code, notes, and snippets.

@eberfreitas
Created January 15, 2011 19:53
Show Gist options
  • Save eberfreitas/781189 to your computer and use it in GitHub Desktop.
Save eberfreitas/781189 to your computer and use it in GitHub Desktop.
proposed syntax
class Bar extends AwesomeClass {
const FOO = 'Foo';
public $bar = 'Bar';
protected $var = 'Var';
private $secret = 'Secret';
public function init() {
$this->myFunction('Foo');
echo(self::FOO);
}
public function myFunction($arg) {
doSomething();
}
public function string() {
$string = 'Hello World ';
$trimmed = trim($string);
}
protected function globals() {
print($_GET['query']);
print($_POST['data']);
print($_REQUEST['something']);
print($_SESSION['user']);
}
public function dataTypes() {
$string = 'string';
$array = array('item', 'anotherItem');
$dict = array('key' => 'value', 'another key' => 'another value');
$dict['newKey'] = 'some other value';
$dict['some other key'] = 'testing';
}
public function shortCuts() {
$___TMP___ = explode('Foo|Bar|Foo|Bar');
$foo = $___TMP___['1'];
print($foo);
}
public function regularPhp() {
$variable = 'Something';
}
}
class Bar extends AwesomeClass
const FOO = 'Foo'
bar = 'Bar' //without the visibility indicator, it defaults to public
protected var = 'Var'
private secret = 'Secret'
//but if you want, you can declare public
public func init()
this.myFunction('Foo')
echo(self::FOO)
func myFunction(arg)
doSomething()
private func string()
string = 'Hello World '
trimmed = string.trim()
protected func globals()
print(_GET.query)
print(_POST.data)
print(_REQUEST.something)
print(_SESSION.user)
func dataTypes()
string = 'string'
//arrays can't have custom keys
array = ['item', 'anotherItem']
//this would be a stdObj or an array
dict = {key: 'value', 'another key': 'another value'}
dict.newKey = 'some other value'
dict.'some other key' = 'testing'
func shortCuts()
foo = 'Foo|Bar|Foo|Bar'.explode('|')[1]
print(foo) //outputs 'Bar'
func regularPhp()
<<<
$variable = 'Something';
>>>
@polarblau
Copy link

Would the indentation matter? If so, you could maybe use something similar to Ruby's syntax?

func myFunction(arg)
    doSomething()

private // indented underneath will be private

    func foo()
        string = 'Hello World '
        trimmed = string.trim()

    func bar()
        string = 'Hello World '
        trimmed = string.trim()

@eberfreitas
Copy link
Author

@polarblau I would rather think of a syntax that resembles php's rather than twist it all around... IMHO, defining visibility currently is not broken on php.

@polarblau
Copy link

I see your point. Maybe I just like Ruby too much :D .
Good luck — really looking forward to seeing where you take this.

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