diff options
| -rw-r--r-- | haxe.html.markdown | 472 | ||||
| -rw-r--r-- | hu-hu/go.html.markdown | 22 | ||||
| -rw-r--r-- | javascript.html.markdown | 2 | ||||
| -rw-r--r-- | perl.html.markdown | 118 | ||||
| -rw-r--r-- | tr-tr/php-tr.html.markdown | 682 | 
5 files changed, 1284 insertions, 12 deletions
| diff --git a/haxe.html.markdown b/haxe.html.markdown new file mode 100644 index 00000000..90b2e250 --- /dev/null +++ b/haxe.html.markdown @@ -0,0 +1,472 @@ +--- +language: haxe +filename: LearnHaxe3.hx +contributors: +    - ["Justin Donaldson", "https://github.com/jdonaldson/"] +--- + +Haxe is a web-oriented language that provides platform support for C++, C#, +Swf/ActionScript, Javascript, Java, and Neko byte code (also written by the +Haxe author).  Note that this guide is for Haxe version 3.  Some of the guide +may be applicable to older versions, but it is recommended to use other +references. + +```haxe +/* +   Welcome to Learn Haxe 3 in 15 minutes.  http://www.haxe.org +   This is an executable tutorial.  You can compile and run it using the haxe +   compiler, while in the same directory as LearnHaxe.hx: +   haxe -main LearnHaxe3 -x out + */ + +// Let's start with comments... this is a single line comment + +/* +   And this is multiline. Multiline comments are also used to generate +   javadoc-style documentation for haxedoc.  They will be used if they precede +   a class, class function, or class variable. + */ + +/* +   A package declaration isn't necessary, but it's useful if you want to +   organize your code into modules later on.  Also worth mentioning, all +   expressions in Haxe must end in a semicolon: + */ +package; // empty package, no namespace. + + +// if you import code from other files, it must be declared before the rest of +// the code. +import haxe.ds.ArraySort; + +// you can import many classes/modules at once with "*" +import haxe.ds.*; + +// you can also import classes in a special way, enabling them to extend the +// functionality of other classes.  More on this later. +using StringTools; + +// Haxe files typically define classes, although they can also define other +// types of code... more on that later. + + +class LearnHaxe3{ +    /* +       If you want certain code to run automatically, you need to put it in +       a static main function, and specify the class in the compiler arguments. +       In this case, we've specified the "LearnHaxe3" class in the compiler +       arguments above. +     */ +    static function main(){ +        /* +           Trace is the default method of printing haxe expressions to the +           screen.  Different targets will have different methods of +           accomplishing this.  E.g., java, c++, c#, etc. will print to std +           out.  Javascript will print to console.log, and flash will print to +           an embedded TextField.  All traces come with a default newline. +           Finally, It's possible to prevent traces from showing by using the +           "--no-traces" argument on the compiler. +         */ + + +        trace("Hello World, with trace()!"); + +        /* +           Trace can handle any type of value or object.  It will try to print +           a representation of the expression as best it can.  You can also +           concatenate strings with the "+" operator: +         */ +        trace( +            " Integer: " + 10 + +            " Float: " + 3.14 + +            " Boolean: " + true +            ); + + +        /* +           Remember what I said about expressions needing semicolons? You +           can put more than one expression on a line if you want. +         */ +        trace('two expressions..'); trace('one line'); + + +        ////////////////////////////////////////////////////////////////// +        // Types & Variables +        ////////////////////////////////////////////////////////////////// +        trace("***Types & Variables***"); + +        /* +           You can save values and references to data structures using the +           "var" keyword: +         */ + +        var an_integer:Int = 1; +        trace(an_integer + " is the value for an_integer"); + + +        /* +           Haxe is statically typed, so "an_integer" is declared to have an +           "Int" type, and the rest of the expression assigns the value "1" to +           it.  It's not necessary to declare the type in many cases.  Here, +           the haxe compiler is inferring that the type of another_integer +           should be "Int". +         */ + +        var another_integer = 2; +        trace(another_integer + " is the value for another_integer"); + +        // The $type() method prints the type that the compiler assigns: +        $type(another_integer); + +        // You can also represent integers with hexadecimal: +        var hex_integer = 0xffffff; + +        /* +           Haxe uses platform precision for Int and Float sizes.  It also +           uses the platform behavior for overflow. +           (Other numeric types and behavior are possible using special +           libraries) +         */ + +        /* +           In addition to simple values like Integers, Floats, and Booleans, +           Haxe provides standard library implementations for common data +           structures like strings, arrays, lists, and maps: +         */ + +        var a_string = "some" + 'string';  // strings can have double or single quotes +        trace(a_string + " is the value for a_string"); + +        var x = 1; +        var an_interpolated_string = 'the value of x is $x'; + +        /* +           Strings are immutable, instance methods will return a copy of +           parts or all of the string. +           (See also the StringBuf class). +         */ +        var a_sub_string = a_string.substr(0,4); +        trace(a_sub_string + " is the value for a_sub_string"); + +        /* +           Arrays are zero-indexed, dynamic, and mutable.  Missing values are +           defined as null. +         */ +        var a = new Array<String>(); // an array that contains Strings +        a[0] = 'foo'; +        trace(a.length + " is the value for a.length"); +        a[9] = 'bar'; +        trace(a.length + " is the value for a.length (after modification)"); +        trace(a[3] + " is the value for a[3]"); //null + +        /* +           Arrays are *generic*, so you can indicate which values they contain +           with a type parameter: +         */ +        var a2 = new Array<Int>(); // an array of Ints +        var a3 = new Array<Array<String>>(); // an Array of Arrays (of Strings). + +        /* +           Maps are simple key/value data structures.  The key and the value +           can be of any type. +         */ +        var m = new Map<String, Int>();  // The keys are strings, the values are Ints. +        m.set('foo', 4); +        // You can also use array notation; +        m['bar'] = 5; +        trace(m.exists('bar') + " is the value for m.exists('bar')"); +        trace(m.get('bar') + " is the value for m.get('bar')"); +        trace(m['bar'] + " is the value for m['bar']"); + +        var m2 =  ['foo' => 4, 'baz' => 6]; // Alternative map syntax +        trace(m2 + " is the value for m2"); + +        /* +           Remember, you can use type inference.  The Haxe compiler will +           decide the type of the variable the first time you pass an +           argument that sets a type parameter. +         */ +        var m3 = new Map(); +        m3.set(6, 'baz'); // m3 is now a Map<Int,String> +        trace(m3 + " is the value for m3"); + +        /* +           Haxe has many more common datastructures in the haxe.ds module, such as +           List, Stack, and BalancedTree +         */ + + +        ////////////////////////////////////////////////////////////////// +        // Operators +        ////////////////////////////////////////////////////////////////// + +        trace("***OPERATORS***"); + +        // basic arithmetic +        trace((4 + 3) + " is the value for (4 + 3)"); +        trace((5 - 1) + " is the value for (5 - 1)"); +        trace((2 * 4) + " is the value for (2 * 4)"); +        trace((8 / 4) + " is the value for (8 / 3) (division always produces Floats)"); +        trace((12 % 4) + " is the value for (12 % 4)"); + + +        //basic comparison +        trace((3 == 2) + " is the value for 3 == 2"); +        trace((3 != 2) + " is the value for 3 != 2"); +        trace((3 >  2) + " is the value for 3 > 2"); +        trace((3 <  2) + " is the value for 3 < 2"); +        trace((3 >= 2) + " is the value for 3 >= 2"); +        trace((3 <= 2) + " is the value for 3 <= 2"); + +        //bitwise operators +        /* +        ~       Unary bitwise complement +        <<      Signed left shift +        >>      Signed right shift +        >>>     Unsigned right shift +        &       Bitwise AND +        ^       Bitwise exclusive OR +        |       Bitwise inclusive OR +        */ + +        //increments +        var i = 0; +        trace("Increments and decrements"); +        trace(i++); //i = 1. Post-Incrementation +        trace(++i); //i = 2. Pre-Incrementation +        trace(i--); //i = 1. Post-Decrementation +        trace(--i); //i = 0. Pre-Decrementation + +        ////////////////////////////////////////////////////////////////// +        // Control Structures +        ////////////////////////////////////////////////////////////////// +        trace("***CONTROL STRUCTURES***"); + +        // if statements +        var j = 10; +        if (j == 10){ +            trace("this is printed"); +        } else if (j > 10){ +            trace("not greater than 10, so not printed"); +        } else { +            trace("also not printed."); +        } + +        trace("Looping and Iteration"); + +        // while loop +        var k = 0; +        while(k < 100){ +            // trace(counter); // will print out numbers 0-99 +            k++; +        } + +        // do-while loop +        var  l = 0; +        do{ +            trace("do statement always runs at least once"); +        } while (i > 0); + +        // for loop +        /* +           There is no c-style for loop in Haxe, because they are prone +           to error, and not necessary.  Instead, Haxe has a much simpler +           and safer version that uses Iterators (more on those later). +         */ +        var m = [1,2,3]; +        for (val in m){ +            trace(val + " is the value for val in the m array"); +        } + +        // Note that you can iterate on an index using a range +        // (more on ranges later as well) +        var n = ['foo', 'bar', 'baz']; +        for (val in 0...n.length){ +            trace(val + " is the value for val (an index for m)"); +        } + + +        trace("Array Comprehensions"); + +        // Array comprehensions give you the ability to iterate over arrays +        // while also creating filters and modifications. +        var filtered_n = [for (val in n) if (val != "foo") val]; +        trace(filtered_n + " is the value for filtered_n"); + +        var modified_n = [for (val in n) val += '!']; +        trace(modified_n + " is the value for modified_n"); + +        var filtered_and_modified_n = [for (val in n) if (val != "foo") val += "!"]; +        trace(filtered_and_modified_n + " is the value for filtered_and_modified_n"); + +        ////////////////////////////////////////////////////////////////// +        // Switch Statements (Value Type) +        ////////////////////////////////////////////////////////////////// +        trace("***SWITCH STATEMENTS (VALUE TYPES)***"); + +        /* +           Switch statements in Haxe are very powerful.  In addition to working +           on basic values like strings and ints, they can also work on the +           generalized algebraic data types in enums (more on enums later). +           Here's some basic value examples for now: +         */ +        var my_dog_name = 'fido'; +        var favorite_thing  = ''; +        switch(my_dog_name){ +            case "fido" : favorite_thing = 'bone'; +            case "rex" :  favorite_thing = 'shoe'; +            case "spot" : favorite_thing = 'tennis ball'; +            case _ : favorite_thing = 'some unknown treat'; +        } +        // The "_" case above is a "wildcard" value +        // that will match anything. + +        trace("My dog's name is" + my_dog_name +                + ", and his favorite thing is a: " +                + favorite_thing); + +        ////////////////////////////////////////////////////////////////// +        // Expression Statements +        ////////////////////////////////////////////////////////////////// +        trace("***EXPRESSION STATEMENTS***"); + +        /* +           Haxe control statements are very powerful because every statement +           is also an expression, consider: +        */ + +        // if statements +        var k = if (true){ +            10; +        } else { +            20; +        } + +        trace("K equals ", k); // outputs 10 + +        var other_favorite_thing = switch(my_dog_name) { +            case "fido" : 'teddy'; +            case "rex" :  'stick'; +            case "spot" : 'football'; +            case _ : 'some unknown treat'; +        } + +        trace("My dog's name is" + my_dog_name +                + ", and his other favorite thing is a: " +                + other_favorite_thing); + +        ////////////////////////////////////////////////////////////////// +        // Converting Value Types +        ////////////////////////////////////////////////////////////////// + +        // You can convert strings to ints fairly easily. + +        // string to integer +        Std.parseInt("0"); // returns 0 +        Std.parseFloat("0.4"); // returns 0.4; + +        // integer to string +        Std.string(0); // returns "0"; +        // concatenation with strings will auto-convert to string. +        0 + "";  // returns "0"; +        true + ""; // returns "true"; +        // See documentation for parsing in Std for more details. + +        ////////////////////////////////////////////////////////////////// +        // Basic Object Oriented Programming +        ////////////////////////////////////////////////////////////////// +        trace("***BASIC OBJECT ORIENTED PROGRAMMING***"); + + +        // create an instance of FooClass.  The classes for this are at the +        // end of the file. +        var instance = new FooClass(3); + +        // read the public variable normally +        trace(instance.public_any + " is the value for instance.public_any"); + +        // we can read this variable +        trace(instance.public_read + " is the value for instance.public_read"); +        // but not write it +        // instance.public_write = 4; // this will throw an error if uncommented: +        // trace(instance.public_write); // as will this. + +        trace(instance + " is the value for instance"); // calls the toString method +        trace(instance.toString() + " is the value for instance.toString()"); // same thing + + +        // instance has the "FooClass" type, while acceptBaseFoo has the +        // BaseFooClass type.  However, since FooClass extends BaseFooClass, +        // it is accepted. +        BaseFooClass.acceptBaseFoo(instance); +    } + +} + +/* +   This is the "child class" of the main LearnHaxe3 Class + */ +class FooClass extends BaseFooClass implements BaseFooInterface{ +    public var public_any:Int; // public variables are accessible anywhere +    public var public_read (default,null): Int; // use this style to only enable public read +    public var public_write (null, default): Int; // or public write +    public var property (get, set): Int; // use this style to enable getters/setters + +    // private variables are not available outside the class. +    // see @:allow for ways around this. +    var _private:Int; // variables are private if they are not marked public + +    // a public constructor +    public function new(arg:Int){ +        super(); // call the constructor of the parent object, since we extended BaseFooClass + +        this.public_any= 0; +        this._private = arg; + +    } + +    // getter for _private +    function get_property() : Int { +        return _private; +    } + +    // setter for _private +    function set_property(val:Int) : Int { +        _private = val; +        return val; +    } + +    // special function that is called whenever an instance is cast to a string. +    public function toString(){ +        return _private + " with toString() method!"; +    } + +    // this class needs to have this function defined, since it implements +    // the BaseFooInterface interface. +    public function baseFunction(x: Int) : String{ +        // convert the int to string automatically +        return x + " was passed into baseFunction!"; +    } +} + +/* +    A simple class to extend +*/ +class BaseFooClass { +    var base_variable:Int; +    public function new(){ +        base_variable = 4; +    } +    public static function acceptBaseFoo(b:BaseFooClass){ +    } +} + +/* +    A simple interface to implement +*/ +interface BaseFooInterface{ +    public function baseFunction(x:Int):String; +} + +``` + diff --git a/hu-hu/go.html.markdown b/hu-hu/go.html.markdown index 460e23ec..69849858 100644 --- a/hu-hu/go.html.markdown +++ b/hu-hu/go.html.markdown @@ -14,7 +14,7 @@ praktikus megoldást nyújt a valós, üzleti problémákra.  C-szerű szintaktikával és statikus típuskezeléssel rendelkezik.  A fordító szempillantás alatt végez és egy gyorsan futó,statikus futtatható állományt hoz létre. -A nyelv könnyen érthető, üzenet-alapú konkurenciát tesz lehetővé, így könnyen ki lehet használni +A nyelv könnyen érthető, folyamatok közötti csatornákon áthaladó üzenetekkel kommunikáló konkurens programozást tesz lehetővé, így könnyen ki lehet használni  a mai számítógépek több magos processzorait, ez nagy rendszerek építéséhez ideális.  A Go alap könyvtára mindenre területre kiterjed, ennek köszönhetően a nyelvnek egyre növekvő tábora van. @@ -77,7 +77,7 @@ func learnMultiple(x, y int) (sum, prod int) {  // Beépített típusok  func learnTypes() { -    // Rövid deklarás az esetek többségében elég lesz a változókhoz +    // Rövid deklarálás az esetek többségében elég lesz a változókhoz      s := "Tanulj Go-t!" // string típus      s2 := `A "nyers" stringekben lehetnek @@ -90,7 +90,7 @@ func learnTypes() {      f := 3.14195 // float64, az IEEE-754 szabványnak megfelelő 64-bites                   // lebegőpontos szám -    c := 3 + 4i  // complex128, belsőleg két float64-el tárolva +    c := 3 + 4i  // complex128, belsőleg két float64-gyel tárolva      // Var szintaxis változó típus definiálással      var u uint = 7 // unsigned, az implementáció dönti el mekkora, akárcsak az @@ -107,7 +107,7 @@ func learnTypes() {      // Szeleteknek dinamikus a méretük. A szeleteknek és a tömböknek is meg      // vannak az előnyeik de a szeleteket sokkal gyakrabban használjuk. -    s3 := []int{4, 5, 9}    // vesd össze a3-al, nincsenek pontok. +    s3 := []int{4, 5, 9}    // vesd össze a3-mal, nincsenek pontok.      s4 := make([]int, 4)    // allokál 4 int-et, mind 0-ra inicializálva      var d2 [][]float64      // ez csak deklaráció, semmi sincs még allokálva      bs := []byte("a slice") // típus konverzió szintaxisa @@ -179,9 +179,9 @@ func learnFlowControl() {          break    // csak vicceltem          continue // soha nem fut le      } -    // Akárcsak a for-nál, az if-ben is lehet rövid deklarással egy lokális -    // változót létrehozni ami az blokk összes if/else-n keresztül érvényes -    // marad. + +    //Akárcsak a for-nál, az if-nél is lehet rövid deklarálással egy lokális változót létrehozni,  +    //ami a blokk összes if/else szerkezetén keresztül érvényes marad.       if y := expensiveComputation(); y > x {          x = y      } @@ -212,8 +212,7 @@ type pair struct {      x, y int  } -// Definiáljunk egy metódust a pair struktúrának, ezzel teljesítve a Stringer -// interf +// Definiáljunk egy metódust a pair struktúrának, ezzel teljesítve a Stringer interfészt.  func (p pair) String() string { // p lesz a "vevő"      // Sprintf az fmt csomag egy publikus függvénye, műkődése megegyezik a C-s      // megfelelőjével. A pontokkal érjük el a mindenkori p struktúra elemeit @@ -312,13 +311,13 @@ func learnWebProgramming() {      // A ListenAndServe első paramétre egy TCP port, amin kiszolgálunk majd.      // Második paramétere egy interfész, pontosabban a http.Handler interfész.      err := http.ListenAndServe(":8080", pair{}) -    fmt.Println(err) // nem felejtük el kiírni az esetleges hibákat! +    fmt.Println(err) // nem felejtjük el kiírni az esetleges hibákat!  }  // Csináljunk a pair-ból egy http.Handler-t úgy, hogy implementáljuk az  // egyetlen metódusát a ServeHTTP-t.  func (p pair) ServeHTTP(w http.ResponseWriter, r *http.Request) { -    // Minden kapcsolatra elküldjük ezt a http.ResponseWriter-el +    // Minden kapcsolatra elküldjük ezt a http.ResponseWriter-rel      w.Write([]byte("Megtanultad a Go-t Y perc alatt!"))  }  ``` @@ -333,3 +332,4 @@ A nyelv specifikációját kifejezetten érdemes olvasni, viszonylag rövid és  Ha pedig jobban bele akarod vetni magad a Go-ba, akkor a standard könyvtárban a legjobb praktikákat kilesheted.  TIPP: a dokumentációban kattints egy funkció nevére és rögtön megmutatja a hozzá tartozó kódot! +Ha pedig a nyelvnek egy bizonyos részéről szeretnél hasonló leírást találni, akkor a [gobyexample.com](https://gobyexample.com/)-on megtalálod, amit keresel.  diff --git a/javascript.html.markdown b/javascript.html.markdown index fb79949e..1dd6e2be 100644 --- a/javascript.html.markdown +++ b/javascript.html.markdown @@ -342,7 +342,7 @@ myPrototype.meaningOfLife = 43;  myObj.meaningOfLife; // = 43  // We mentioned that __proto__ was non-standard, and there's no standard way to -// change the prototype of an existing object. However, there's two ways to +// change the prototype of an existing object. However, there are two ways to  // create a new object with a given prototype.  // The first is Object.create, which is a recent addition to JS, and therefore diff --git a/perl.html.markdown b/perl.html.markdown new file mode 100644 index 00000000..024bd851 --- /dev/null +++ b/perl.html.markdown @@ -0,0 +1,118 @@ +--- +name: perl +category: language +language: perl +filename: learnperl.pl +contributors: +    - ["Korjavin Ivan", "http://github.com/korjavin"] +--- + +Perl 5 is a highly capable, feature-rich programming language with over 25 years of development. + +Perl 5 runs on over 100 platforms from portables to mainframes and is suitable for both rapid prototyping and large scale development projects. + +```perl +# Single line comments start with a hash. + + +#### Perl variable types + +#  Variables begin with the $ symbol. +#  A valid variable name starts with a letter or underscore, +#  followed by any number of letters, numbers, or underscores. + +### Perl has three main variable types: scalars, arrays, and hashes. + +## Scalars +#  A scalar represents a single value: +my $animal = "camel"; +my $answer = 42; + +# Scalar values can be strings, integers or floating point numbers, and Perl will automatically convert between them as required. + +## Arrays +#  An array represents a list of values: +my @animals = ("camel", "llama", "owl"); +my @numbers = (23, 42, 69); +my @mixed   = ("camel", 42, 1.23); + + + +## Hashes +#   A hash represents a set of key/value pairs: + +my %fruit_color = ("apple", "red", "banana", "yellow"); + +#  You can use whitespace and the "=>" operator to lay them out more nicely: + +my %fruit_color = ( +        apple  => "red", +        banana => "yellow", +        ); +# Scalars, arrays and hashes are documented more fully in perldata. (perldoc perldata). + +# More complex data types can be constructed using references, which allow you to build lists and hashes within lists and hashes. + +#### Conditional and looping constructs + +# Perl has most of the usual conditional and looping constructs. + +if ( $var ) { +    ... +} elsif ( $var eq 'bar' ) { +    ... +} else { +    ... +} + +unless ( condition ) { +                   ... +               } +# This is provided as a more readable version of "if (!condition)" + +# the Perlish post-condition way +print "Yow!" if $zippy; +print "We have no bananas" unless $bananas; + +#  while +  while ( condition ) { +                   ... +               } + + +# for and foreach +for ($i = 0; $i <= $max; $i++) { +                   ... +               } + +foreach (@array) { +                   print "This element is $_\n"; +               } + + +#### Regular expressions + +# Perl's regular expression support is both broad and deep, and is the subject of lengthy documentation in perlrequick, perlretut, and elsewhere.  However, in short: + +# Simple matching +if (/foo/)       { ... }  # true if $_ contains "foo" +if ($a =~ /foo/) { ... }  # true if $a contains "foo" + +# Simple substitution + +$a =~ s/foo/bar/;         # replaces foo with bar in $a +$a =~ s/foo/bar/g;        # replaces ALL INSTANCES of foo with bar in $a + + +``` + +#### Using Perl modules + +Perl modules provide a range of features to help you avoid reinventing the wheel, and can be downloaded from CPAN ( http://www.cpan.org/ ).  A number of popular modules are included with the Perl distribution itself. + +perlfaq contains questions and answers related to many common tasks, and often provides suggestions for good CPAN modules to use. + +#### Further Reading + +[Learn at www.perl.com](http://www.perl.org/learn.html) + and perldoc perlintro diff --git a/tr-tr/php-tr.html.markdown b/tr-tr/php-tr.html.markdown new file mode 100644 index 00000000..94bc31ff --- /dev/null +++ b/tr-tr/php-tr.html.markdown @@ -0,0 +1,682 @@ +--- +language: php +filename: learnphp-tr.php +contributors: +    - ["Malcolm Fell", "http://emarref.net/"] +    - ["Trismegiste", "https://github.com/Trismegiste"] +translators: +    - ["Haydar KULEKCI", "http://scanf.info/"] +lang: tr-tr +--- + +PHP 5+ versiyonu için geçerlidir. + +```php +<?php // PHP kodları <?php etiketleri içerisinde bulunmalıdır. + +// Eğer php dosyanız sadece PHP kodu içeriyorsa, php'nin kapatma  +// etiketini kapatmayabilirsiniz.  + +// // işareti ile tek satırlık yorum satırı başlar. + +# # işareti de aynı görevi görür ancak // daha genel kullanımdadır. + + + +/* +    Çoklu satır kodu bu şekilde yazıyoruz. slash yıldız ile başlar  +    ve yıldız slash ile biter. +*/ + +// "echo" ya da "print" metodları çıktı almak için kullanılır. +print('Hello '); // Ekrana Yeni satır karakteri olmadan "Hello "  +                 // yazdırılır. + +// () parantezler "echo" ve "print" metodları için isteğe bağlıdır.  +echo "World\n"; // Ekrana yeni satır karakteri olmadan "World" +                // yazdırılır. +// (Bütün ifadeler noktalı virgül ile bitmelidir.) + +// <?php tagı dışarısındaki herşey otomatik olarak yazdırılacaktır. +?> +Hello World Again! +<?php + + +/************************************ +*   Tipler ve Değişkenler +*************************************/ + +// Değişkenler $ sembolü ile başlar. +// Geçerli bir değişken bir harf veya alt çizgi ile başlar, +// devamında da bir sayı, harf veya alt çizgi ile devam eder.  + +// Mantıksal değerler  +// Boolean values are harf büyüklüğüne duyarsızdır. +$boolean = true;  // veya TRUE veya True +$boolean = false; // veya FALSE veya False + +// Tam Sayılar +$int1 = 12;   // => 12 +$int2 = -12;  // => -12 +$int3 = 012;  // => 10 (öneki 0 olan sekizlik(octal) bir sayıyı gösterir) +$int4 = 0x0F; // => 15 (öneki 0x olanlar hex sayıları gösterir.) + +// Kayan Noktalı Sayılar +$float = 1.234; +$float = 1.2e3; +$float = 7E-10; + +// Aritmetik +$sum        = 1 + 1; // 2 +$difference = 2 - 1; // 1 +$product    = 2 * 2; // 4 +$quotient   = 2 / 1; // 2 + +// Aritmetik Kısayolları +$number = 0; +$number += 1;      // $number değişkeninin değerini 1 artırır. +echo $number++;    // 1 yazdırılır. (Yazdırıldıktan sonra artırılır.) +echo ++$number;    // 3 yazdırılır. (yazdırılmadan önce artırılır.) +$number /= $float; // Bölünür ve bölüm $number değerine eşitlenir. + +// Karakter dizileri(strings) tek tırnak ile kullanılmalıdır. +$sgl_quotes = '$String'; // => '$String' + +// Bir değişken içermediği sürece çift tırnak kullanmaktan kaçının +$dbl_quotes = "This is a $sgl_quotes."; // => 'This is a $String.' + +// Özel karakterler sadece çift tırnak ile kullanılabilir. +$escaped   = "This contains a \t tab character."; +$unescaped = 'This just contains a slash and a t: \t'; + +// Gerekirse bir değişkeni küme ayracı içine alın. +$money = "I have $${number} in the bank."; + +// Since PHP 5.3, nowdocs can be used for uninterpolated multi-liners +$nowdoc = <<<'END' +Multi line +string +END; + +// Heredocs will do string interpolation +$heredoc = <<<END +Multi line +$sgl_quotes +END; + +// . işareti ile karakter dizileri birbirine birleştirilebilir. +echo 'This string ' . 'is concatenated'; + + +/******************************** + * Sabitler + */ + +// Bir sabit define() metodu kullanılarak tanımlanır. +// ve çalışma zamanından hiçbir zaman değişmez! + +// geçerli bir sabit bir harf veya altçizgi ile başlar, +// ve bir sayı, harf ya da altçizgi ile devam eder. +define("FOO",     "something"); + +// sabite ulaşmak için direk olarak seçilen ismi kullanabilirsiniz.  +echo 'This outputs '.FOO; + + +/******************************** + * Diziler + */ + +// PHP'de bütün diziler ilişikilendirilebilirdir. (hashmaps), +// İlişkilendirilebilir(associative) diziler, hashmap olarak bilinir.  + +// PHP'nin bütün versiyonları için çalışır +$associative = array('One' => 1, 'Two' => 2, 'Three' => 3); + +// PHP 5.4 ile yeni bir söz dizimi kullanılmaya başlandı +$associative = ['One' => 1, 'Two' => 2, 'Three' => 3]; + +echo $associative['One']; // 1 yazdıracaktır. + +// Liste kullanımında index'ler tam sayıdır. +$array = ['One', 'Two', 'Three']; +echo $array[0]; // => "One" + + +/******************************** + * Çıktı + */ + +echo('Hello World!'); +// Hello World! çıktısı stdout'a yazdırılır. +// Eğer bir web browser ile çalışıyorsanır Stdout bir web sayfasıdır. + +print('Hello World!'); // echo ile aynıdır. + +// Aslında echo bir dil sabitidir, parantezleri kullanmayabilirsiniz.  +echo 'Hello World!'; +print 'Hello World!'; // Bu yazdırılacaktır.  + +$paragraph = 'paragraph'; + +echo 100;        // Echo ile doğrudan sayısal değer kullanımı +echo $paragraph; // veya değişken + +// PHP 5.4.0 veya daha üstü sürümlerde kısa açılış etiketi  +// konfigürasyonları yapıldı ise, kısa açılış etiketini kullanabilirsiniz. +?> +<p><?= $paragraph ?></p> +<?php + +$x = 1; +$y = 2; +$x = $y; // Şu anda $x değişkeni $y ile aynı değere sahiptir. +$z = &$y; +// $z, $y'nin referansını içermektedir.  +// $z'nin değerinin değişmesi $y'nin değerinide değiştireceltir veya +// tam tersi. Ancak $x özgün değeri olarak kalacaktır. + +echo $x; // => 2 +echo $z; // => 2 +$y = 0; +echo $x; // => 2 +echo $z; // => 0 + +/******************************** + * Mantık + */ +$a = 0; +$b = '0'; +$c = '1'; +$d = '1'; + +// Argüman doğru değilse bir hata fırlatılacaktır. + +// Bu karşılaştırmalar tipler aynı olmasa bile her zaman true olacaktır. +assert($a == $b); // equality +assert($c != $a); // inequality +assert($c <> $a); // alternative inequality +assert($a < $c); +assert($c > $b); +assert($a <= $b); +assert($c >= $d); + +// Aşağıdakiler yanlızca değer ve tip aynı olduğunda true olacaktır. +assert($c === $d); +assert($a !== $d); +assert(1 == '1'); +assert(1 !== '1'); + +// Değişkenler kullanıma bağlı olarak farklı tiplere çevrilebilir. + +$integer = 1; +echo $integer + $integer; // => 2 + +$string = '1'; +echo $string + $string; // => 2 (Karakter dizisi tam sayıya çevrilmeye zorlanır) + +$string = 'one'; +echo $string + $string; // => 0 +// Çıktı 0 olacaktır, çünkü + operatörü karakter dizisi olan 'one' değerini +// bir sayıya çeviremez. + +// Veri tipi çevirileri bir değişkeni farklı bir türde  +// düzenlemek için kullanılabilir. + +$boolean = (boolean) 1; // => true + +$zero = 0; +$boolean = (boolean) $zero; // => false + +// Veri tiplerini çevirmek için bazı fonksiyonlar vardır. +$integer = 5; +$string = strval($integer); + +$var = null; // Null değeri. + + +/******************************** + * Kontrol Yapıları + */ + +if (true) { +    print 'I get printed'; +} + +if (false) { +    print 'I don\'t'; +} else { +    print 'I get printed'; +} + +if (false) { +    print 'Does not get printed'; +} elseif(true) { +    print 'Does'; +} + +// Üçlü operatör +print (false ? 'Does not get printed' : 'Does'); + +$x = 0; +if ($x === '0') { +    print 'Does not print'; +} elseif($x == '1') { +    print 'Does not print'; +} else { +    print 'Does print'; +} + + + +// Bu alternatif sözdizimi template'ler için kullanışlıdır. +?> + +<?php if ($x): ?> +This is displayed if the test is truthy. +<?php else: ?> +This is displayed otherwise. +<?php endif; ?> + +<?php + +// Use switch to save some logic. +switch ($x) { +    case '0': +        print 'Switch does type coercion'; +        break; // Bir breake yazmalısınız ya da 'two' ve 'three' +               // durumunuda kapsarsınız. +    case 'two': +    case 'three': +        // $variable değişkeni 'two' ya da 'three' ise  +        break; +    default: +        // Varsayılan olarak bir şey yap +} + +// While, do...while ve for döngüleri tanıdıktır. +$i = 0; +while ($i < 5) { +    echo $i++; +}; // "01234" yazdırılacaktır + +echo "\n"; + +$i = 0; +do { +    echo $i++; +} while ($i < 5); // "01234" yazdırılacaktır. + +echo "\n"; + +for ($x = 0; $x < 10; $x++) { +    echo $x; +} // "0123456789" yazdırılacaktır. + +echo "\n"; + +$wheels = ['bicycle' => 2, 'car' => 4]; + +// Foreach döngüsü diziler üzerinde çalışır +foreach ($wheels as $wheel_count) { +    echo $wheel_count; +} // "24" yazdırılacaktır. + +echo "\n"; + +// Key-Value değerlere ulaşabilirsiniz. +foreach ($wheels as $vehicle => $wheel_count) { +    echo "A $vehicle has $wheel_count wheels"; +} + +echo "\n"; + +$i = 0; +while ($i < 5) { +    if ($i === 3) { +        break; // while döngüsünden çıkar +    } +    echo $i++; +} // Prints "012" + +for ($i = 0; $i < 5; $i++) { +    if ($i === 3) { +        continue; // Aktif döngüyü atlar  +    } +    echo $i; +} // "0124" yazdırılacaktır. + + + +/******************************** + * Fonksiyonlar + */ + +// Bir fonksiyon tanımlamak için "function" kullanılır: +function my_function () { +  return 'Hello'; +} + +echo my_function(); // => "Hello" + +// Geçerli bir fonksiyon ismi bir harf veya altçizgi ile başlar ve +// bir sayı, harf ya da alt çizgi ile devam eder. + +function add ($x, $y = 1) { // $y değeri isteğe bağlıdır ve  +                            // varsayılan değeri 1'dir +  $result = $x + $y; +  return $result; +} + +echo add(4); // => 5 +echo add(4, 2); // => 6 + +// $result fonksiyon dışında ulaşılabilir değildir.  +// print $result; // Bir uyarı verecektir. + +// PHP 5.3'den beri bir anonymous fonksiyon tanımlayabilirsiniz; +$inc = function ($x) { +  return $x + 1; +}; + +echo $inc(2); // => 3 + +function foo ($x, $y, $z) { +  echo "$x - $y - $z"; +} + +// Fonksiyonlar bir fonksiyon dönebilir. +function bar ($x, $y) { +  // Fonksiyona dışardan değişken gönderebilmek için 'use' komutunu kullanın. +  return function ($z) use ($x, $y) { +    foo($x, $y, $z); +  }; +} + +$bar = bar('A', 'B'); +$bar('C'); // "A - B - C" yazdırılacaktır. + +// Fonksiyonun ismini karakter dizinden çağırabilirsiniz.  +$function_name = 'add'; +echo $function_name(1, 2); // => 3 +// Programatik olarak fonksiyonları çalıştırmak için yararlı olabilir +// veya, call_user_func(callable $callback [, $parameter [, ... ]]); kulanın. + + +/******************************** + * Includes + */ + +<?php +// PHP'de include edilecek dosyalar PHP açma etiketi ile başlamalı. (!) + +include 'my-file.php'; +// my-file.php dosyasındaki kodlar artık mevcut scope'da kullanılabilir. +// Eğer dosya include edilemezse bir uyarı (örneğin: file not found)  +// fırlatılacaktır. + +include_once 'my-file.php'; +// Eğer bir dosya include edildi ise tekrar include edilmeyecektir. +// Bu çoklu class tanımlama hatalarını önler. + +require 'my-file.php'; +require_once 'my-file.php'; +// Dosya include edilemediğinde fatal error veren require() bu konu  +// dışında include() ile aynıdır. + +// my-include.php dosyasının içeriği: +<?php + +return 'Anything you like.'; +// Dosya sonu + +// Include'lar ver require'lar aynı zamanda bir return dönebilir. +$value = include 'my-include.php'; + +// Dosyalar verilen dosya yoluna göre include edilir veya, hiçbirşey  +// verilmezse include_path konfigürasyonuna göre include edecektir.  +// Eğer dosya include_path'da da bulunamazsa include hata vermeden  +// önce içinde bulunulan dizini kontrol ecektir. +/* */ + + +/******************************** + * Sınıflar + */ + +// Sınıflar class kelimesi ile tanımlanır + +class MyClass +{ +    const MY_CONST      = 'value'; // Bir sabit + +    static $staticVar   = 'static'; + +    // Static değişkenler ve onların görünürlüğü +    public static $publicStaticVar = 'publicStatic'; +    private static $privateStaticVar = 'privateStatic';  +        // Sadece bu sınıf içerisinde erişilebilir +    protected static $protectedStaticVar = 'protectedStatic';  +        // Bu sınıf ve alt sınıflarından erişilebilir + +    // Özellikler görünürlüğü ile birlikte tanımlanmalıdır. +    public $property    = 'public'; +    public $instanceProp; +    protected $prot = 'protected'; // Sınıf ve alt sınıflardan erişilebilir +    private $priv   = 'private';   // Sadece bu sınıftan erişilebilir + +    // __construct ile bir constructor oluşturulabilir. +    public function __construct($instanceProp) { +        // $this ile instance değişkenine erişilir. +        $this->instanceProp = $instanceProp; +    } + +    // Sınıfın içerisinde metodlar fonksiyonlar gibi tanımlanır. +    public function myMethod() +    { +        print 'MyClass'; +    } + +    final function youCannotOverrideMe() +    { +    } + +    public static function myStaticMethod() +    { +        print 'I am static'; +    } +} + +echo MyClass::MY_CONST;    // 'value' şeklinde çıktı verir; +echo MyClass::$staticVar;  // 'static' şeklinde çıktı verir; +MyClass::myStaticMethod(); // 'I am static' şeklinde çıktı verir; + +// Sınıfların new ile kullanımı +$my_class = new MyClass('An instance property'); +// Eğer argüman göndermeyeceksek parantezler isteğe bağlıdır. + +// Sınıfın üyelerine erişim -> +echo $my_class->property;     // => "public" +echo $my_class->instanceProp; // => "An instance property" +$my_class->myMethod();        // => "MyClass" + + +// "extends" ile sınıfı extend etmek +class MyOtherClass extends MyClass +{ +    function printProtectedProperty() +    { +        echo $this->prot; +    } + +    // Bir methodu ezmek +    function myMethod() +    { +        parent::myMethod(); +        print ' > MyOtherClass'; +    } +} + +$my_other_class = new MyOtherClass('Instance prop'); +$my_other_class->printProtectedProperty(); // "protected" şeklinde çıktı verir. +$my_other_class->myMethod();    // "MyClass > MyOtherClass" şeklinde çıktı verir + +final class YouCannotExtendMe +{ +} + +// getter ve setter'ları oluşturmak için "magic method"ları kullanabilirsiniz. +class MyMapClass +{ +    private $property; + +    public function __get($key) +    { +        return $this->$key; +    } + +    public function __set($key, $value) +    { +        $this->$key = $value; +    } +} + +$x = new MyMapClass(); +echo $x->property; // __get() metodunu kullanacaktır. +$x->property = 'Something'; // __set() metodunu kullanacaktır.  + +// Sınıflar abstract olabilir(abstract kelimesini kullanarak) veya +// interface'ler uygulanabilir (implements kelimesi kullanılarak). +// Bir interface "interface" kelimesi kullanılarak oluşturulur. + +interface InterfaceOne +{ +    public function doSomething(); +} + +interface InterfaceTwo +{ +    public function doSomethingElse(); +} + +// interfaces can be extended +interface InterfaceThree extends InterfaceTwo +{ +    public function doAnotherContract(); +} + +abstract class MyAbstractClass implements InterfaceOne +{ +    public $x = 'doSomething'; +} + +class MyConcreteClass extends MyAbstractClass implements InterfaceTwo +{ +    public function doSomething() +    { +        echo $x; +    } + +    public function doSomethingElse() +    { +        echo 'doSomethingElse'; +    } +} + + +// Sınıflar birden fazla interface kullanabilir. +class SomeOtherClass implements InterfaceOne, InterfaceTwo +{ +    public function doSomething() +    { +        echo 'doSomething'; +    } + +    public function doSomethingElse() +    { +        echo 'doSomethingElse'; +    } +} + + + +/******************************** + * Traits + */ +// Trait'ler PHP 5.4.0'dan beri kullanılabilir ve "trait" kullanılarak  +// tanımlanır. + +trait MyTrait +{ +    public function myTraitMethod() +    { +        print 'I have MyTrait'; +    } +} + +class MyTraitfulClass +{ +    use MyTrait; +} + +$cls = new MyTraitfulClass(); +$cls->myTraitMethod(); // "I have MyTrait" çıktısını verir. + + + +/******************************** + * İsim Uzayları + */ + +// Bu alan ayrılmıştır, çünkü isim uzayı tanımı bir dosyada en başta  +// yapılmalıdır. Bu örnekte böyle olmadığını varsayalım. + +<?php + +// Varsayılan olarak, sınıflar global isim uzayındadır, ve açıkça bir  +// ters slash ile çağrılabilir. + +$cls = new \MyClass(); + + + +// Bir dosya için isim uzayı atama +namespace My\Namespace; + +class MyClass +{ +} + +// (diğer bir dosya) +$cls = new My\Namespace\MyClass; + +//veya diğer bir isim uzayında. +namespace My\Other\Namespace; + +use My\Namespace\MyClass; + +$cls = new MyClass(); + +// veya isim uzayına bir takma isim koyabilirsiniz. + +namespace My\Other\Namespace; + +use My\Namespace as SomeOtherNamespace; + +$cls = new SomeOtherNamespace\MyClass(); + +*/ + +``` + +## Daha fazla bilgi + +Referans ve topluluk yazıları için [official PHP documentation](http://www.php.net/manual/) adresini ziyaret edin. + +Gncel en yi örnekler için [PHP Usulüne Uygun](http://kulekci.net/php-the-right-way/) adresini ziyaret edin. + +Eğer bir paket yöneticisi olan dil kullandıysanız, [Composer](http://getcomposer.org/)'a bir göz atın. + +Genel standartlar için PHP Framework Interoperability Group'unun [PSR standards](https://github.com/php-fig/fig-standards) ziyaret edebilirsiniz.  + | 
