cvs: phpdoc /he/language oop.xml
| From: | Barak Bloch | Date: | Sun, 27 Jan 2002 00:08:00 +0000 |
| Subject: | cvs: phpdoc /he/language oop.xml | ||
| Groups: | php.doc | ||
| Request: | Send a blank email to phpdoc+get-969341646@lists.php.net to get a copy of this message | ||
barak Sat Jan 26 19:08:00 2002 EDT
Modified files:
/phpdoc/he/language oop.xml
Log:
most of file, was translated, but with a lot of mistakes... still work on it
Index: phpdoc/he/language/oop.xml diff -u phpdoc/he/language/oop.xml:1.1 phpdoc/he/language/oop.xml:1.2 --- phpdoc/he/language/oop.xml:1.1 Fri Jan 25 19:54:53 2002 +++ phpdoc/he/language/oop.xml Sat Jan 26 19:08:00 2002 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.1 $ --> +<!-- $Revision: 1.2 $ --> <chapter id="language.oop"> <title>Classes and Objects</title> @@ -251,7 +251,7 @@ </sect1> <sect1 id="language.oop.constructor"> - <title><literal>Constructors</literal></title> + <title><literal>áðàéí</literal></title> <caution> <simpara> @@ -446,10 +446,10 @@ </caution> <para> - ìòéúéí æä ùéîåùé ìäúééçñ ì functions and variables - in base classes or to refer to functions in classes that - have not yet any instances. The :: operator is being used - for this. + ìòéúéí æä ùéîåùé ìáöò ééçåñ ìîùúðéí åôåð÷öéåú áîçì÷ú + äáñéñ àå ìäùúîù áééçåñ ìôåð÷öéåú àùø ðîöàåú áîçì÷åú + ùòãééï ìà éöøðå ìäï îåôò (òãééï ìà îåîù ìäï àåáéé÷è). + äàåôøèåø :: îùîù ìáéöåò îùéîä æàú. </para> <informalexample> @@ -472,15 +472,15 @@ } } -// there is no object of class A. -// this will print +// àéï àåáéé÷è ìîçì÷ä A. +// îä ùäåìê ìäéåú îåãôñ ìñîñê æä: // I am the original function A::example().<br> A::example(); -// create an object of class B. +// éöéøú àåáéé÷è (ùäåà "îåôò") ìîçì÷ä B. $b = new B; -// this will print +// îä ùéåãôñ ëúåöàä îëê æä: // I am the redefined function B::example().<br> // I am the original function A::example().<br> $b->example(); @@ -489,60 +489,60 @@ </informalexample> <para> - The above example calls the function example() in - class A, but there is no object of class A, so that - we cannot write $a->example() or similar. Instead we - call example() as a 'class function', that is, as a - function of the class itself, not any object of that - class. + äãåâîà ùìîòìä ÷åøàú ìôåð÷öéä example() ùáúåê + äîçì÷ä A, àáì àéï àåáéé÷è ìîçì÷ä A, åìôéëê + ìà ðéúï ìëúåá $a->example() àå îùäå ãåîà. áî÷åí æàú + ÷øàðå ìôåð÷öéä example() ë 'ôåð÷öéú îçì÷ä', ëìåîø, äéà + îùîùú ëôåð÷öéä ùì äîçì÷ä òöîä, ììà àåáé÷è ëìùäå ùì + àåúä îçì÷ä. </para> <para> - There are class functions, but there are no class variables. - In fact, there is no object at all at the time of the call. - Thus, a class function may not use any object variables (but - it can use local and global variables), and it may no use - $this at all. + éù ôåð÷öéåú áîçì÷ä, àáì àéï îùúðéí áîçì÷ä. + ìîòùä, àéï àåáéé÷è ëìùäå áæîï áå ð÷øà äôåð÷öéä + ìëï, ôåð÷öéåú ùì äîçì÷ä ìà éëåìåú ìäùúîù áîùúðéí ùì äàåáéé÷è (àáì + äï éëåìåú ìäùúîù áîùúðéí âìåáàìééí åî÷åîééí), åäï ìà éëåìåú ìäùúîù á - + $this ëìì. </para> <para> - In the above example, class B redefines the function example(). - The original definition in class A is shadowed - and no longer available, unless you are refering specifically - to the implementation of example() in class A using the - ::-operator. Write A::example() to do this (in fact, you - should be writing parent::example(), as shown in the next - section). + áãåâîà ùîòì, äîçì÷ä B îâãéøä îçãù àú äôåð÷öéä example(). + ääâãøä äî÷åøéú áúåê äîçì÷ä A "îåöììú" + åìà îú÷ééîú ìîòùä, òã àùø îééçñéí ñôöéôéú + ìîéîåù ùì example() ùáúåê äîçì÷ä A úåê ùéîåù áàåôøèåø + :: . äëúéáä ùì A::example() òåùä æàú (ìîòùä, øöåé + ìëúåá: parent::example(), ëôé ùéåãâí áçì÷ + äáà). </para> <para> - In this context, there is a current object and it may - have object variables. Thus, when used from WITHIN an - object function, you may use $this and object variables. + áä÷ùø æä, ðåöø àåáéé÷è åééúëï ùéäéå + ìå îùúðé àåáéé÷è. ìëï, ëùîùúîùéí áîùúðéí îúåê ôåð÷öéú äàåáéé÷è, + àôùø ìäùúîù á $this åáîùúðé äîçì÷. </para> </sect1> <sect1 id="keyword.parent"> - <title><literal>parent</literal></title> + <title><literal>äåøä</literal></title> <para> - You may find yourself writing code that refers to - variables and functions in base classes. This is - particularly true if your derived class is a refinement - or specialisation of code in your base class. + ìòéúéí ëåúáéí ÷åã ùîéåçñ ì îùúðéí + åôåð÷öéåú àùø ðîöàéí áîçì÷ú áñéñ. îöá æä + îúàéí áîéåçã àí äîçì÷ä äîçìæ÷ä äâæåøä äéà ùëìåì àå + ééùå ñôöéôé éåúø ùì ä÷åã ùðîöà áîç÷ìú äáñéñ. </para> <para> - Instead of using the literal name of the base class in your - code, you should be using the special name - <literal>parent</literal>, which refers to the name of your - base class as given in the <literal>extends</literal> - declation of your class. By doing this, you avoid using the - name of your base class in more than one place. Should - your inheritance tree change during implementation, the - change is easily made by simply changing the - <literal>extends</literal> declaration of your class. + áî÷åí ìäùúîù áùí äîéìåìé (ìéèøìé) ùì äîçì÷ú äáñéñ ùì ä÷åã, + øöåé ìáöò ùéîåù á ùí äîéåçã + <literal>parent</literal>, ùìîòùä îöáéò òì äùí ùì îçì÷ú + äáñéñ ëôé ùðëúáä úåê ùéîåù áäëøæä <literal>extends</literal> + áîçì÷ä ùìê. áòæøú ùéîåù âæä, ðîðòéí îùéîåù áùí + ùì îçì÷ú äáñéñ áéåúø îî÷åí àçã. ëëä, + ëùòåùéí ùéðåé áîéîåù ùì ääåøùåú , + îñôé÷ ìùðåú àú äùí äîåëøæ + <literal>extends</literal> ùðîöà áäëøæä òì äîçì÷ä. </para> <informalexample> @@ -575,45 +575,46 @@ </sect1> <sect1 id="language.oop.serialization"> - <title>Serializing objects - objects in sessions</title> + <title>"àåáéé÷èéí áäîùëéí" - àåáéé÷èéí á session</title> <note> <simpara> - In PHP 3, objects will lose their class association - throughout the process of serialization and unserialization. - The resulting variable is of type object, but has no class - and no methods, thus it is pretty useless (it has become - just like an array with a funny syntax). + á PHP 3, àåáé÷èéí éàáãå àú äùéåê ìîçì÷ä ùìäí + áîäìê äúäìéê ùì "ôøñåí áäîùëéí" (serializatio) å "àé ôøñåí áäîùëéí" + (unserialization). + äúåöàä äéà îùúðä îñåâ àåáéé÷è, àáì ììà îçì÷ä + åììà îúåãåú (ôåð÷öéåú ùì äîçì÷ä), ìëï æä îîù ìà ùéîåùé (æä ìîòùä ðäéä + îîù ëîå îòøê òí úçáéø îùòùò). </simpara> </note> <caution> <simpara> - The following information is valid for PHP 4 only. + äîéãò áäîùê ú÷ó ì - PHP 4 áìáã. </simpara> </caution> <para> - <function>serialize</function> returns a string containing a - byte-stream representation of any value that can be stored in - PHP. <function>unserialize</function> can use this string to - recreate the original variable values. Using serialize to - save an object will save all variables in an object. The - functions in an object will not be saved, only the name of - the class. + <function>serialize</function> îçæéø îçøåæú ùîëéìä + "ùèó áúéí" ùîééåöâåú òì éãé òøê ëìùäå ùéëåì ìäéåú ùîåø á + PHP. <function>unserialize</function> îùúîùéí áîçøåæú æå + ìéöéøä îçãù ùì äòøëéí äî÷åøéí ùì îùúðä. ùéîåù á serialize + ìùîøéú äàåáéé÷è úùîåø úùîåø àú ëì äîùúðéí ùáàåáéé÷è. + äôåð÷öéåú ùáàåáéé÷è ìà éùîøå, ø÷ äùí ùì äîçì÷ä + äåà æä ùéùîø. </para> <para> - In order to be able to <function>unserialize</function> an - object, the class of that object needs to be defined. That - is, if you have an object $a of class A on page1.php and - serialize this, you'll get a string that refers to class A - and contains all values of variabled contained in $a. If - you want to be able to unserialize this on page2.php, - recreating $a of class A, the definition of class A must - be present in page2.php. This can be done for example - by storing the class defintion of class A in an include - file and including this file in both page1.php and page2.php. + òì îðú ìäùúîù á <function>unserialize</function> òì + àåáéé÷è, äîçì÷ä ùì àåúå àåáéé÷è öøéëä ìäéåú îîåîùú. åìôéëê, + àí éù àú äàåáéé÷è $a ùì äîçì÷ä A ùáãó page1.php åáåöò + serialize òìéä, úú÷áì îçøåæú ùúééçñ ìîçì÷ä A + åàùø úëéì àú ëì äòøëéí ùì äîùúðéí ä÷ééîéí $a. + ëùéù öåøê ìäùúîù á unserialize ùá page2.php, + éöéøä îçãù ùì äåáéé÷è $a ùì äîçì÷ä A, ääâã÷ä ùì äîçì÷ä A çééáú + ìäéåú îéåöâú á - page2.php. æä éëåì ìäòùåú ìãåâîà òì éãé + àéëñåï ùì äâãøú äîçì÷ä A áúåê ÷åáõ îåëìì + åäëììú ÷åáõ æä âí á page1.php åâí á page2.php. </para> <informalexample> @@ -635,91 +636,90 @@ $a = new A; $s = serialize($a); - // store $s somewhere where page2.php can find it. + // àéëñåï $s áî÷åí ëùìäå ëù page2.php éëåì ìîöåà àåúå. $fp = fopen("store", "w"); fputs($fp, $s); fclose($fp); page2.php: - // this is needed for the unserialize to work properly. + // æä ðãøù òì îðú ìáöò unserialize áöåøä äðëåðä. include("classa.inc"); $s = implode("", @file("store")); $a = unserialize($s); - // now use the function show_one() of the $a object. + // òëùéå äôåð÷öéä show_one() áùéîåù ùì äàåáéé÷è $a. $a->show_one(); ]]> </programlisting> </informalexample> <para> - If you are using sessions and use <function>session_register</function> - to register objects, these objects are serialized automatically - at the end of each PHP page, and are unserialized automatically on - each of the following pages. This basically means that these objects - can show up on any of your pages once they become part of your + àí àúä îùúîù á session åîùúîù á <function>session_register</function> + òì îðú ìàâåø îùúðä, àåáéé÷èéí àìå áàåôï àåèåîèé serialized + áñåó ëì òîåã PHP, åäí unserialized àåèåîèéú + áàçã îëì äãôéí äáàéí. äëååðä äáñéñéú äéà ùäàåáéé÷è + éëåì ìäåôéò áãó ëìãùäå áøâò ùäí äåôòéí ìäéåú çì÷ îúåê ä session. </para> <para> - It is strongly recommended that you include the class - definitions of all such registered objects on all of your - pages, even if you do not actually use these classes on all - of your pages. If you don't and an object is being - unserialized without its class definition being present, it - will lose its class association and become an object of class - <literal>stdClass</literal> without any functions available - at all, that is, it will become quite useless. + îàåã îåîìõ ìäëìéì àú äâãøú äîçì÷ä + ùì ëì äàåáéé÷èéí äîåæîðéí ùì ëì àåúí + ãôéí, âí àí àúä ìà áàîú îùúîù áàåúí îçì÷åú áëì + àåúí ãôéí. àí àúä ìà îùúîù áàåáéé÷è äåà + unserialized ììà äâãøú äîçì÷ä äðåëçéú, äåà + éàáã àú äùéåê ìîçì÷ä åéäôåê ìàåáéé÷è ùì äîçì÷ä + <literal>stdClass</literal> ììà ôåð÷öéä ëùìäé ùîú÷ééîú + áëìì, ìôéëê, äåà éäôê ììà ùéîåùé ëìì. </para> <para> - So if in the example above $a became part of a session by - running <literal>session_register("a")</literal>, you should - include the file <literal>classa.inc</literal> on all of your - pages, not only page1.php and page2.php. + àí áãåâîà ùîòì $a äåôê ìçì÷ î session òêì éãé + ùéîåù á <literal>session_register("a")</literal>, éù öåøê + ìäëìéì àú ä÷åáõ <literal>classa.inc</literal> áëì äãôéí, + ìà ø÷ áãôéí page1.php å page2.php. </para> </sect1> <sect1 id="language.oop.magic-functions"> - <title>The magic functions <literal>__sleep</literal> and <literal>__wakeup</literal></title> + <title>"ôåð÷öéåú ä÷ñí": <literal>__sleep</literal> å <literal>__wakeup</literal></title> <para> - <function>serialize</function> checks if your class has a function with - the magic name <literal>__sleep</literal>. If so, that function is - being run prior to any serialization. It can clean up the object - and is supposed to return an array with the names of all variables - of that object that should be serialized. + <function>serialize</function> áåã÷ àí ìîçì÷ä éù ôåð÷öéä òí + "îéìú ä÷ñí" <literal>__sleep</literal>. àí æä äîöá, ôåð÷öéä æå + îúçéìä ìøåõ ìôðé ëì serialization. äéà éëåìä ìð÷åú àú äàåáéé÷è + åäéà àîåøä ìäçæéø îòøê òí ùîåú ùì äîùúðéí + ùì àåúå àåáéé÷è ùéëåì ìäéåú serialized. </para> <para> - The intended use of <literal>__sleep</literal> is to close any - database connections that object may have, committing pending - data or perform similar cleanup tasks. Also, the function is - useful if you have very large objects which need not be - saved completely. + äéòã ùìù ùéîåù á <literal>__sleep</literal> äåà ìñâåø + çéáåø ëìùäå ìîñã ðúåðéí ùéëåì ìäéåú ìàåáéé÷è, ìáöò îñéøú îéãò + ùàîåø ìäîñø àå ìáöò îùéîåú ðé÷åé ãåîåú. âí, äôåð÷öéä äéà + ùéîåùéú àí éù àåáéé÷è âãåì îàåã ùìà ðãøù ìùîéøä îìàä. </para> <para> - Conversely, <function>unserialize</function> checks for the - presence of a function with the magic name - <literal>__wakeup</literal>. If present, this function can - reconstruct any resources that object may have. + åìäéôê, <function>unserialize</function> áåã÷ ðåëçåú + ùì ôåð÷öéä òí îéìú ä÷ñí + <literal>__wakeup</literal>. àí äîéìä ðåëçú, ôåð÷öéä æå éëåìä + ìáðåú îçãù î÷åø ëìùäå ùéëåì ìäéåú ìàåáéé÷è. </para> <para> - The intended use of <literal>__wakeup</literal> is to - reestablish any database connections that may have been lost - during serialization and perform other reinitialization - tasks. + äùîéîåù á <literal>__wakeup</literal> ðåòâ ìä÷éí îçãù + çéáåø ìîñã ðúåðéí ëùìäå ùòìåì ììëú ìàéáåã + áîäìê serialization åìáöò reinitialization ùì + îùéîä àçøú. </para> </sect1> <sect1 id="language.oop.newref"> - <title>References inside the constructor</title> + <title>ééçåñ ùðëúá ìáðàéí</title> <para> - Creating references within the constructor can lead to confusing - results. This tutorial-like section helps you to avoid problems. + ëúéáú ééçåñ ìáðàéí òìåì ìäåáéì ìúåöàåú îáìáìåú. + çì÷ æä áîãøéê òåæø ìê ìäîðò îäáòéåú ùéúëðå. <informalexample> <programlisting role="php"> @@ -753,11 +753,11 @@ </para> <para> - Let us check out if there is a difference between - <varname>$bar1</varname> which has been created using - the copy <literal>=</literal> operator and - <varname>$bar2</varname> which has been created using - the reference <literal>=&</literal> operator... + áãé÷ä àí éù äáãì áéï + <varname>$bar1</varname> ùéåöø úåê ùéîåù áòåú÷ ùì äàåôøèåø + <literal>=</literal> åùì + <varname>$bar2</varname> ùðåöø úåê ùéîåù áàåôøèåø äééçåñ + <literal>=&</literal> ... <informalexample> <programlisting role="php"> @@ -784,24 +784,24 @@ </informalexample> </para> <para> - Apparently there is no difference, but in fact there is a - very significant one: <varname>$bar1</varname> and - <varname>$globalref[0]</varname> are _NOT_ referenced, they - are NOT the same variable. This is because "new" does not - return a reference by default, instead it returns a copy. + ðøàä ùàéï ëì äáãì, àáì ìîòùä éù äáãì îùîòåúé + îàåù àçã: <varname>$bar1</varname> å + <varname>$globalref[0]</varname> äí ìà îéåçñéí, äí + ìà àåúå îùúðä. æàú áâìì ù "new" ìà îçæéø + éçåñ ááøéøú îçãì, áî÷åí æàú äåà îçæéø òåú÷. <note> <simpara> - There is no performance loss (since PHP 4 and up use reference - counting) returning copies instead of references. On the - contrary it is most often better to simply work with copies - instead of references, because creating references takes some - time where creating copies virtually takes no time (unless none - of them is a large array or object and one of them gets changed - and the other(s) one(s) subsequently, then it would be wise to - use references to change them all concurrently). + àéï àéáåã ùì áéöåòéí (îàçø å PHP 4 åîòìä îùúîùéí áîéñôåø + ìéçåñ) åîåçæøéí òåú÷éí áî÷åí ééçåñ. îöã ùðé + æä ìòúéí ÷øåáåú òãéó ôùåè ìòáåã òí òåú÷éí + áî÷åí òí "ééçåñéí", áâìì ùéöéøú "ééçñåéí" ìå÷çú æîï îä + ëùéöéøú òåú÷éí åéøèåàìéí àéðä ìå÷çú æîï ëìùäå (ëì òåã àó àçã îäí + äåà ìà îòøê âãåì àå àåáéé÷è and åùàçã îäí îùúðä + åàçø(éí) ìàçø îëï, áî÷ø ëæä æä éäéä çëí ìäùúîù + áééçåñéí ìùðåú àú ëåìí áå æîðéú). </simpara> </note> - To prove what is written above let us watch the code below. + ìäåëéç àú îä ùðëúá ìîòìä éù ìáçåï àú ä÷åã äáà: <informalexample> <programlisting role="php"> @@ -834,7 +834,7 @@ </informalexample> </para> <para> - Another final example, try to understand it. + ìáñåó òåã ãåâîà, îåîìõ ìðñåú ìäáéï àåúä. <informalexample> <programlisting role="php">
Index: phpdoc/he/language/oop.xml diff -u phpdoc/he/language/oop.xml:1.1 phpdoc/he/language/oop.xml:1.2 --- phpdoc/he/language/oop.xml:1.1 Fri Jan 25 19:54:53 2002 +++ phpdoc/he/language/oop.xml Sat Jan 26 19:08:00 2002 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.1 $ --> +<!-- $Revision: 1.2 $ --> <chapter id="language.oop"> <title>Classes and Objects</title> @@ -251,7 +251,7 @@ </sect1> <sect1 id="language.oop.constructor"> - <title><literal>Constructors</literal></title> + <title><literal>áðàéí</literal></title> <caution> <simpara> @@ -446,10 +446,10 @@ </caution> <para> - ìòéúéí æä ùéîåùé ìäúééçñ ì functions and variables - in base classes or to refer to functions in classes that - have not yet any instances. The :: operator is being used - for this. + ìòéúéí æä ùéîåùé ìáöò ééçåñ ìîùúðéí åôåð÷öéåú áîçì÷ú + äáñéñ àå ìäùúîù áééçåñ ìôåð÷öéåú àùø ðîöàåú áîçì÷åú + ùòãééï ìà éöøðå ìäï îåôò (òãééï ìà îåîù ìäï àåáéé÷è). + äàåôøèåø :: îùîù ìáéöåò îùéîä æàú. </para> <informalexample> @@ -472,15 +472,15 @@ } } -// there is no object of class A. -// this will print +// àéï àåáéé÷è ìîçì÷ä A. +// îä ùäåìê ìäéåú îåãôñ ìñîñê æä: // I am the original function A::example().<br> A::example(); -// create an object of class B. +// éöéøú àåáéé÷è (ùäåà "îåôò") ìîçì÷ä B. $b = new B; -// this will print +// îä ùéåãôñ ëúåöàä îëê æä: // I am the redefined function B::example().<br> // I am the original function A::example().<br> $b->example(); @@ -489,60 +489,60 @@ </informalexample> <para> - The above example calls the function example() in - class A, but there is no object of class A, so that - we cannot write $a->example() or similar. Instead we - call example() as a 'class function', that is, as a - function of the class itself, not any object of that - class. + äãåâîà ùìîòìä ÷åøàú ìôåð÷öéä example() ùáúåê + äîçì÷ä A, àáì àéï àåáéé÷è ìîçì÷ä A, åìôéëê + ìà ðéúï ìëúåá $a->example() àå îùäå ãåîà. áî÷åí æàú + ÷øàðå ìôåð÷öéä example() ë 'ôåð÷öéú îçì÷ä', ëìåîø, äéà + îùîùú ëôåð÷öéä ùì äîçì÷ä òöîä, ììà àåáé÷è ëìùäå ùì + àåúä îçì÷ä. </para> <para> - There are class functions, but there are no class variables. - In fact, there is no object at all at the time of the call. - Thus, a class function may not use any object variables (but - it can use local and global variables), and it may no use - $this at all. + éù ôåð÷öéåú áîçì÷ä, àáì àéï îùúðéí áîçì÷ä. + ìîòùä, àéï àåáéé÷è ëìùäå áæîï áå ð÷øà äôåð÷öéä + ìëï, ôåð÷öéåú ùì äîçì÷ä ìà éëåìåú ìäùúîù áîùúðéí ùì äàåáéé÷è (àáì + äï éëåìåú ìäùúîù áîùúðéí âìåáàìééí åî÷åîééí), åäï ìà éëåìåú ìäùúîù á - + $this ëìì. </para> <para> - In the above example, class B redefines the function example(). - The original definition in class A is shadowed - and no longer available, unless you are refering specifically - to the implementation of example() in class A using the - ::-operator. Write A::example() to do this (in fact, you - should be writing parent::example(), as shown in the next - section). + áãåâîà ùîòì, äîçì÷ä B îâãéøä îçãù àú äôåð÷öéä example(). + ääâãøä äî÷åøéú áúåê äîçì÷ä A "îåöììú" + åìà îú÷ééîú ìîòùä, òã àùø îééçñéí ñôöéôéú + ìîéîåù ùì example() ùáúåê äîçì÷ä A úåê ùéîåù áàåôøèåø + :: . äëúéáä ùì A::example() òåùä æàú (ìîòùä, øöåé + ìëúåá: parent::example(), ëôé ùéåãâí áçì÷ + äáà). </para> <para> - In this context, there is a current object and it may - have object variables. Thus, when used from WITHIN an - object function, you may use $this and object variables. + áä÷ùø æä, ðåöø àåáéé÷è åééúëï ùéäéå + ìå îùúðé àåáéé÷è. ìëï, ëùîùúîùéí áîùúðéí îúåê ôåð÷öéú äàåáéé÷è, + àôùø ìäùúîù á $this åáîùúðé äîçì÷. </para> </sect1> <sect1 id="keyword.parent"> - <title><literal>parent</literal></title> + <title><literal>äåøä</literal></title> <para> - You may find yourself writing code that refers to - variables and functions in base classes. This is - particularly true if your derived class is a refinement - or specialisation of code in your base class. + ìòéúéí ëåúáéí ÷åã ùîéåçñ ì îùúðéí + åôåð÷öéåú àùø ðîöàéí áîçì÷ú áñéñ. îöá æä + îúàéí áîéåçã àí äîçì÷ä äîçìæ÷ä äâæåøä äéà ùëìåì àå + ééùå ñôöéôé éåúø ùì ä÷åã ùðîöà áîç÷ìú äáñéñ. </para> <para> - Instead of using the literal name of the base class in your - code, you should be using the special name - <literal>parent</literal>, which refers to the name of your - base class as given in the <literal>extends</literal> - declation of your class. By doing this, you avoid using the - name of your base class in more than one place. Should - your inheritance tree change during implementation, the - change is easily made by simply changing the - <literal>extends</literal> declaration of your class. + áî÷åí ìäùúîù áùí äîéìåìé (ìéèøìé) ùì äîçì÷ú äáñéñ ùì ä÷åã, + øöåé ìáöò ùéîåù á ùí äîéåçã + <literal>parent</literal>, ùìîòùä îöáéò òì äùí ùì îçì÷ú + äáñéñ ëôé ùðëúáä úåê ùéîåù áäëøæä <literal>extends</literal> + áîçì÷ä ùìê. áòæøú ùéîåù âæä, ðîðòéí îùéîåù áùí + ùì îçì÷ú äáñéñ áéåúø îî÷åí àçã. ëëä, + ëùòåùéí ùéðåé áîéîåù ùì ääåøùåú , + îñôé÷ ìùðåú àú äùí äîåëøæ + <literal>extends</literal> ùðîöà áäëøæä òì äîçì÷ä. </para> <informalexample> @@ -575,45 +575,46 @@ </sect1> <sect1 id="language.oop.serialization"> - <title>Serializing objects - objects in sessions</title> + <title>"àåáéé÷èéí áäîùëéí" - àåáéé÷èéí á session</title> <note> <simpara> - In PHP 3, objects will lose their class association - throughout the process of serialization and unserialization. - The resulting variable is of type object, but has no class - and no methods, thus it is pretty useless (it has become - just like an array with a funny syntax). + á PHP 3, àåáé÷èéí éàáãå àú äùéåê ìîçì÷ä ùìäí + áîäìê äúäìéê ùì "ôøñåí áäîùëéí" (serializatio) å "àé ôøñåí áäîùëéí" + (unserialization). + äúåöàä äéà îùúðä îñåâ àåáéé÷è, àáì ììà îçì÷ä + åììà îúåãåú (ôåð÷öéåú ùì äîçì÷ä), ìëï æä îîù ìà ùéîåùé (æä ìîòùä ðäéä + îîù ëîå îòøê òí úçáéø îùòùò). </simpara> </note> <caution> <simpara> - The following information is valid for PHP 4 only. + äîéãò áäîùê ú÷ó ì - PHP 4 áìáã. </simpara> </caution> <para> - <function>serialize</function> returns a string containing a - byte-stream representation of any value that can be stored in - PHP. <function>unserialize</function> can use this string to - recreate the original variable values. Using serialize to - save an object will save all variables in an object. The - functions in an object will not be saved, only the name of - the class. + <function>serialize</function> îçæéø îçøåæú ùîëéìä + "ùèó áúéí" ùîééåöâåú òì éãé òøê ëìùäå ùéëåì ìäéåú ùîåø á + PHP. <function>unserialize</function> îùúîùéí áîçøåæú æå + ìéöéøä îçãù ùì äòøëéí äî÷åøéí ùì îùúðä. ùéîåù á serialize + ìùîøéú äàåáéé÷è úùîåø úùîåø àú ëì äîùúðéí ùáàåáéé÷è. + äôåð÷öéåú ùáàåáéé÷è ìà éùîøå, ø÷ äùí ùì äîçì÷ä + äåà æä ùéùîø. </para> <para> - In order to be able to <function>unserialize</function> an - object, the class of that object needs to be defined. That - is, if you have an object $a of class A on page1.php and - serialize this, you'll get a string that refers to class A - and contains all values of variabled contained in $a. If - you want to be able to unserialize this on page2.php, - recreating $a of class A, the definition of class A must - be present in page2.php. This can be done for example - by storing the class defintion of class A in an include - file and including this file in both page1.php and page2.php. + òì îðú ìäùúîù á <function>unserialize</function> òì + àåáéé÷è, äîçì÷ä ùì àåúå àåáéé÷è öøéëä ìäéåú îîåîùú. åìôéëê, + àí éù àú äàåáéé÷è $a ùì äîçì÷ä A ùáãó page1.php åáåöò + serialize òìéä, úú÷áì îçøåæú ùúééçñ ìîçì÷ä A + åàùø úëéì àú ëì äòøëéí ùì äîùúðéí ä÷ééîéí $a. + ëùéù öåøê ìäùúîù á unserialize ùá page2.php, + éöéøä îçãù ùì äåáéé÷è $a ùì äîçì÷ä A, ääâã÷ä ùì äîçì÷ä A çééáú + ìäéåú îéåöâú á - page2.php. æä éëåì ìäòùåú ìãåâîà òì éãé + àéëñåï ùì äâãøú äîçì÷ä A áúåê ÷åáõ îåëìì + åäëììú ÷åáõ æä âí á page1.php åâí á page2.php. </para> <informalexample> @@ -635,91 +636,90 @@ $a = new A; $s = serialize($a); - // store $s somewhere where page2.php can find it. + // àéëñåï $s áî÷åí ëùìäå ëù page2.php éëåì ìîöåà àåúå. $fp = fopen("store", "w"); fputs($fp, $s); fclose($fp); page2.php: - // this is needed for the unserialize to work properly. + // æä ðãøù òì îðú ìáöò unserialize áöåøä äðëåðä. include("classa.inc"); $s = implode("", @file("store")); $a = unserialize($s); - // now use the function show_one() of the $a object. + // òëùéå äôåð÷öéä show_one() áùéîåù ùì äàåáéé÷è $a. $a->show_one(); ]]> </programlisting> </informalexample> <para> - If you are using sessions and use <function>session_register</function> - to register objects, these objects are serialized automatically - at the end of each PHP page, and are unserialized automatically on - each of the following pages. This basically means that these objects - can show up on any of your pages once they become part of your + àí àúä îùúîù á session åîùúîù á <function>session_register</function> + òì îðú ìàâåø îùúðä, àåáéé÷èéí àìå áàåôï àåèåîèé serialized + áñåó ëì òîåã PHP, åäí unserialized àåèåîèéú + áàçã îëì äãôéí äáàéí. äëååðä äáñéñéú äéà ùäàåáéé÷è + éëåì ìäåôéò áãó ëìãùäå áøâò ùäí äåôòéí ìäéåú çì÷ îúåê ä session. </para> <para> - It is strongly recommended that you include the class - definitions of all such registered objects on all of your - pages, even if you do not actually use these classes on all - of your pages. If you don't and an object is being - unserialized without its class definition being present, it - will lose its class association and become an object of class - <literal>stdClass</literal> without any functions available - at all, that is, it will become quite useless. + îàåã îåîìõ ìäëìéì àú äâãøú äîçì÷ä + ùì ëì äàåáéé÷èéí äîåæîðéí ùì ëì àåúí + ãôéí, âí àí àúä ìà áàîú îùúîù áàåúí îçì÷åú áëì + àåúí ãôéí. àí àúä ìà îùúîù áàåáéé÷è äåà + unserialized ììà äâãøú äîçì÷ä äðåëçéú, äåà + éàáã àú äùéåê ìîçì÷ä åéäôåê ìàåáéé÷è ùì äîçì÷ä + <literal>stdClass</literal> ììà ôåð÷öéä ëùìäé ùîú÷ééîú + áëìì, ìôéëê, äåà éäôê ììà ùéîåùé ëìì. </para> <para> - So if in the example above $a became part of a session by - running <literal>session_register("a")</literal>, you should - include the file <literal>classa.inc</literal> on all of your - pages, not only page1.php and page2.php. + àí áãåâîà ùîòì $a äåôê ìçì÷ î session òêì éãé + ùéîåù á <literal>session_register("a")</literal>, éù öåøê + ìäëìéì àú ä÷åáõ <literal>classa.inc</literal> áëì äãôéí, + ìà ø÷ áãôéí page1.php å page2.php. </para> </sect1> <sect1 id="language.oop.magic-functions"> - <title>The magic functions <literal>__sleep</literal> and <literal>__wakeup</literal></title> + <title>"ôåð÷öéåú ä÷ñí": <literal>__sleep</literal> å <literal>__wakeup</literal></title> <para> - <function>serialize</function> checks if your class has a function with - the magic name <literal>__sleep</literal>. If so, that function is - being run prior to any serialization. It can clean up the object - and is supposed to return an array with the names of all variables - of that object that should be serialized. + <function>serialize</function> áåã÷ àí ìîçì÷ä éù ôåð÷öéä òí + "îéìú ä÷ñí" <literal>__sleep</literal>. àí æä äîöá, ôåð÷öéä æå + îúçéìä ìøåõ ìôðé ëì serialization. äéà éëåìä ìð÷åú àú äàåáéé÷è + åäéà àîåøä ìäçæéø îòøê òí ùîåú ùì äîùúðéí + ùì àåúå àåáéé÷è ùéëåì ìäéåú serialized. </para> <para> - The intended use of <literal>__sleep</literal> is to close any - database connections that object may have, committing pending - data or perform similar cleanup tasks. Also, the function is - useful if you have very large objects which need not be - saved completely. + äéòã ùìù ùéîåù á <literal>__sleep</literal> äåà ìñâåø + çéáåø ëìùäå ìîñã ðúåðéí ùéëåì ìäéåú ìàåáéé÷è, ìáöò îñéøú îéãò + ùàîåø ìäîñø àå ìáöò îùéîåú ðé÷åé ãåîåú. âí, äôåð÷öéä äéà + ùéîåùéú àí éù àåáéé÷è âãåì îàåã ùìà ðãøù ìùîéøä îìàä. </para> <para> - Conversely, <function>unserialize</function> checks for the - presence of a function with the magic name - <literal>__wakeup</literal>. If present, this function can - reconstruct any resources that object may have. + åìäéôê, <function>unserialize</function> áåã÷ ðåëçåú + ùì ôåð÷öéä òí îéìú ä÷ñí + <literal>__wakeup</literal>. àí äîéìä ðåëçú, ôåð÷öéä æå éëåìä + ìáðåú îçãù î÷åø ëìùäå ùéëåì ìäéåú ìàåáéé÷è. </para> <para> - The intended use of <literal>__wakeup</literal> is to - reestablish any database connections that may have been lost - during serialization and perform other reinitialization - tasks. + äùîéîåù á <literal>__wakeup</literal> ðåòâ ìä÷éí îçãù + çéáåø ìîñã ðúåðéí ëùìäå ùòìåì ììëú ìàéáåã + áîäìê serialization åìáöò reinitialization ùì + îùéîä àçøú. </para> </sect1> <sect1 id="language.oop.newref"> - <title>References inside the constructor</title> + <title>ééçåñ ùðëúá ìáðàéí</title> <para> - Creating references within the constructor can lead to confusing - results. This tutorial-like section helps you to avoid problems. + ëúéáú ééçåñ ìáðàéí òìåì ìäåáéì ìúåöàåú îáìáìåú. + çì÷ æä áîãøéê òåæø ìê ìäîðò îäáòéåú ùéúëðå. <informalexample> <programlisting role="php"> @@ -753,11 +753,11 @@ </para> <para> - Let us check out if there is a difference between - <varname>$bar1</varname> which has been created using - the copy <literal>=</literal> operator and - <varname>$bar2</varname> which has been created using - the reference <literal>=&</literal> operator... + áãé÷ä àí éù äáãì áéï + <varname>$bar1</varname> ùéåöø úåê ùéîåù áòåú÷ ùì äàåôøèåø + <literal>=</literal> åùì + <varname>$bar2</varname> ùðåöø úåê ùéîåù áàåôøèåø äééçåñ + <literal>=&</literal> ... <informalexample> <programlisting role="php"> @@ -784,24 +784,24 @@ </informalexample> </para> <para> - Apparently there is no difference, but in fact there is a - very significant one: <varname>$bar1</varname> and - <varname>$globalref[0]</varname> are _NOT_ referenced, they - are NOT the same variable. This is because "new" does not - return a reference by default, instead it returns a copy. + ðøàä ùàéï ëì äáãì, àáì ìîòùä éù äáãì îùîòåúé + îàåù àçã: <varname>$bar1</varname> å + <varname>$globalref[0]</varname> äí ìà îéåçñéí, äí + ìà àåúå îùúðä. æàú áâìì ù "new" ìà îçæéø + éçåñ ááøéøú îçãì, áî÷åí æàú äåà îçæéø òåú÷. <note> <simpara> - There is no performance loss (since PHP 4 and up use reference - counting) returning copies instead of references. On the - contrary it is most often better to simply work with copies - instead of references, because creating references takes some - time where creating copies virtually takes no time (unless none - of them is a large array or object and one of them gets changed - and the other(s) one(s) subsequently, then it would be wise to - use references to change them all concurrently). + àéï àéáåã ùì áéöåòéí (îàçø å PHP 4 åîòìä îùúîùéí áîéñôåø + ìéçåñ) åîåçæøéí òåú÷éí áî÷åí ééçåñ. îöã ùðé + æä ìòúéí ÷øåáåú òãéó ôùåè ìòáåã òí òåú÷éí + áî÷åí òí "ééçåñéí", áâìì ùéöéøú "ééçñåéí" ìå÷çú æîï îä + ëùéöéøú òåú÷éí åéøèåàìéí àéðä ìå÷çú æîï ëìùäå (ëì òåã àó àçã îäí + äåà ìà îòøê âãåì àå àåáéé÷è and åùàçã îäí îùúðä + åàçø(éí) ìàçø îëï, áî÷ø ëæä æä éäéä çëí ìäùúîù + áééçåñéí ìùðåú àú ëåìí áå æîðéú). </simpara> </note> - To prove what is written above let us watch the code below. + ìäåëéç àú îä ùðëúá ìîòìä éù ìáçåï àú ä÷åã äáà: <informalexample> <programlisting role="php"> @@ -834,7 +834,7 @@ </informalexample> </para> <para> - Another final example, try to understand it. + ìáñåó òåã ãåâîà, îåîìõ ìðñåú ìäáéï àåúä. <informalexample> <programlisting role="php">