diff --git a/_static/docs.css b/_static/docs.css index 4b4fd34..aff0f78 100755 --- a/_static/docs.css +++ b/_static/docs.css @@ -1,10 +1,19 @@ +html { + background: none; +} + body { color: #333333; - font-family: "Open Sans",sans-serif; - font-size: 13px; - line-height: 1.231; - text-align: center; + font-family: "Open Sans","Helvetica Neue",Helvetica,Arial,sans-serif; + font-size: 14px; + line-height: 22px; + margin: 0 0 11px; +} + +#nav-main { + background-color: #2C2C2C; + background-image: -moz-linear-gradient(center top , #333333, #222222); } h2 { @@ -18,14 +27,15 @@ h2 { margin: 25px 0 0; } -p, li { - color: #434343; - font-size: 16px; - line-height: 24px; - margin-left: 0; - min-height: 0; +h3 { + font-weight: 600; + margin: 15px 0 10px; } +/*p, li { + color: #434343; +}*/ + td.primary-box li { padding: 0px; line-height: 16px; @@ -122,7 +132,7 @@ div.related li.right { } div.related li.right a { - background: #339A6B; + background: none repeat scroll 0 0 #0088CC; padding: 10px; border-radius: 5px; color: #fff; @@ -133,7 +143,9 @@ div.related li.right a { } p.versionadded { - background: none repeat scroll 0 0 #A8CEBB; + color: #468847; + background-color: #dff0d8; + border-color: #d6e9c6; font-size: 15px; margin-left: 20px; margin-right: 20px; @@ -163,14 +175,13 @@ span.versionmodified { font-style: italic; } -div.highlight { +/*div.highlight { background: none repeat scroll 0 0 #212121; margin: 7px 5px 5px; max-width: 95%; overflow-x: scroll; text-align: left; margin-left: 0px; - /*padding: 5px;*/ } div.highlight, @@ -199,7 +210,7 @@ blockquote p { font-size: 14px; line-height: 18px; color: #DCDCCC; -} +}*/ p.topless { margin: 0px; @@ -218,8 +229,7 @@ div.figure { color: #EFDCBC; } -.highlight .k, -.highlight .kt { +.highlight .k { color: #F0DFAF; font-weight: bold; } @@ -240,7 +250,8 @@ div.figure { .highlight .s, .highlight .s1, -.highlight .s2 { +.highlight .s2, +.highlight .sb { color: #CC9393; } @@ -263,7 +274,8 @@ div.figure { } .highlight .mi, -.highlight .mf { +.highlight .mf, +.highlight .m { color: #8CD0D3; } @@ -290,27 +302,36 @@ div.figure { color: #DADADA; } +.highlight .si { + color: #EFDCBC; + font-style: italic; +} + +.highlight .kd { + color: #919191; +} + table.docutils { border-collapse: collapse; - border-top: 1px solid #ABABAB; - border-left: 1px solid #ABABAB; + border-top: 1px solid #DDDDDD; + border-left: 1px solid #DDDDDD; margin-left: auto; margin-right: auto; - width: 90%; + width: 95%; margin-bottom: 15px; + border-radius: 4px; } table.docutils td, table.docutils th { color: #434343; - border-bottom: 1px solid #ABABAB; - border-right: 1px solid #ABABAB; - font-size: 1.2em; + border-bottom: 1px solid #DDDDDD; + border-right: 1px solid #DDDDDD; padding: 5px; } table.docutils th { - background: none repeat scroll 0 0 #DADADA; + background: none repeat scroll 0 0 #F9F9F9; text-align: center; } @@ -319,3 +340,152 @@ table.docutils tr { margin: 0px; } +div#methods h2, +div#constants h2 { + color: #999999; +} + +div#methods a, +div#constants a, { + text-decoration: none; +} + +div#methods a:hover { + text-decoration: underline; +} + +div#methods em, +div#constants em { + color: #0088CC; +} + +p.method-desc { + margin-left: 25px; + font-size: 14px; + margin-bottom: 20px; + margin-top: 10px; +} + +div#methods span.modifier { + color: #267B0C; +} + +div#methods span.inherited { + color: #999999; + font-style: italic; +} + +em { + font-style: normal; +} + +p.versionchanged, blockquote.highlights { + background-color: #D9EDF7; + border-color: #BCE8F1; + color: #3A87AD; +} + +div#footer { + padding: 50px 10px; + background: none repeat scroll 0 0 #006DA5; + font-size: 12px; +} + +div#footer p { + display: block; + margin: 0px; + font-size: 12px; +} + +div.highlight, blockquote { + font-family: Monaco,Menlo,Consolas,"Courier New",monospace; + background-color: #F5F5F5; + border: 1px solid rgba(0, 0, 0, 0.15); + border-radius: 4px 4px 4px 4px; + display: block; + font-size: 13px; + line-height: 17px; + margin: 0 0 11px; + padding: 5px; + padding-left: 10px; + word-wrap: break-word; +} + +div.highlight { + word-break: break-all; +} + +.highlight .sd { + color: #717171; + font-weight: normal; +} + +.highlight .k { + color: #1E347B; + font-weight: normal; +} + +.highlight .nf, +.highlight .nc { + color: #48484C; + font-weight: normal; +} + +.highlight .nv { + color: #48484C; +} + +.highlight .nx, +.highlight .na, +.highlight .nb { + color: teal; +} + +.highlight .s, .highlight .s1, .highlight .s2, .highlight .sb { + color: #DD1144; +} + +.highlight .c1, .highlight .cm { + color: #93A1A1; + font-style: italic; +} + +.highlight .o { + color: #1E347B; +} + +.highlight .cp { + color: rgba(0, 0, 0, 0.4); +} + +.highlight .nt { + color: #1E347B; + font-weight: normal; +} + +.highlight .si { + color: coral; + font-weight: normal; +} + +.highlight .mi, .highlight .mf, .highlight .m { + color: teal; +} + +.highlight .ni { + color: teal; + font-weight: bold; +} + +.highlight .kn { + color: #000000; + font-weight: normal; +} + +.highlight .sr { + color: #717171; +} + +pre { + font-family: Monaco,Menlo,Consolas,"Courier New",monospace; +} diff --git a/conf.py b/conf.py index 84245ed..41a5063 100755 --- a/conf.py +++ b/conf.py @@ -48,10 +48,10 @@ # built documents. # # The short X.Y version. -version = '0.5.x' +version = '1.0.x' # The full version, including alpha/beta/rc tags. -release = '0.5.0' +release = '1.0.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/index.rst b/index.rst index 521db04..57dac46 100755 --- a/index.rst +++ b/index.rst @@ -2,7 +2,9 @@ Welcome to Phalcon Internals ============================ -Phalcon is not a traditional framework, it's written as an C extension for PHP to provide high performance. The purpose of this document is to explain how it is built internally. If you're interested in helping to improve Phalcon, or simply understand how it works, this is the information you need. +Phalcon is not a traditional framework, it's written as an C extension for PHP to provide high performance. +The purpose of this document is to explain how it is built internally. If you're interested in helping improve Phalcon, +or simply understand how it works, this is the information you need. Other formats ------------- diff --git a/reference/arrays.rst b/reference/arrays.rst index 265c9a5..3ff1a09 100644 --- a/reference/arrays.rst +++ b/reference/arrays.rst @@ -1,6 +1,7 @@ Working with Arrays =================== -Although the Zend API, and provides various functions for working with arrays, with Phalcon API we added others. Specifically helping to maintain the reference counting correctly: +Although the Zend API provides several functions for working with arrays, the Phalcon API has added others. +Specifically helping to maintain the reference counting correctly: One dimension Arrays ^^^^^^^^^^^^^^^^^^^^ diff --git a/reference/classes.rst b/reference/classes.rst index 854428a..e1f5fba 100644 --- a/reference/classes.rst +++ b/reference/classes.rst @@ -1,10 +1,13 @@ Classes ======= -As an object oriented framework, Phalcon is mostly composed of classes. The classes are organized into namespaces. The following are the steps to export a variable in the extension and also make it available for other classes inside the framework. +As an object oriented framework, Phalcon is mostly composed of classes. The classes are organized into namespaces. +The following are the steps to export a variable in the extension and also make it available for other classes +inside the framework. Registering methods and its arguments ------------------------------------- -In the dev/php_phalcon.h register in the first part of the file the pointer to the zend class entry. Let's pretend we're adding a Phalcon\\Auth to the framework: +In the dev/php_phalcon.h register in the first part of the file the pointer to the zend class entry. Let's pretend +we're adding a Phalcon\\Auth to the framework: .. code-block:: c @@ -18,7 +21,8 @@ Then, we can add the methods prototypes, it's neccesary to add all the methods t PHP_METHOD(Phalcon_Auth, getIdentity); PHP_METHOD(Phalcon_Auth, auth); -Later in the same file add the information of the arguments of each method. For example, let's define the class constructor only takes two arguments and they're mandatory: +Later in the same file add the information of the arguments of each method. For example, let's define the class +constructor only takes two arguments and they're mandatory: .. code-block:: c @@ -64,7 +68,9 @@ Each class has its own file .c file, in the case of Phalcon\\Auth file would be PHALCON_MM_RESTORE(); } -With the above code we create the constructor of the class Phalcon\\Auth, a method is defined with the macro PHP_METHOD, first we put the class name and then the name of the method, although Phalcon uses namespaces, class names have _ instead of \\: +With the above code we create the constructor of the class Phalcon\\Auth, a method is defined with the macro +PHP_METHOD, first we put the class name and then the name of the method, although Phalcon uses namespaces, +class names have _ instead of \\: .. code-block:: c @@ -79,7 +85,9 @@ If the method has parameters we receive them using zend_parse_parameters: RETURN_NULL(); } -If we do not receive the correct number of parameters will result in an error message. You see, there's an argument "zz" to receive the parameters, this indicates the type of data received and the number of them. In the above example that means that the method is receiving two parameters. If it were three zval then it should be "zzz". +If we do not receive the correct number of parameters will result in an error message. You see, there's an argument +"zz" to receive the parameters, this indicates the type of data received and the number of them. In the above example +that means that the method is receiving two parameters. If they were three zval then it should be "zzz". Then the variables are received in respective order: &adapter_name, &options diff --git a/reference/exceptions.rst b/reference/exceptions.rst index 24233ae..760c854 100644 --- a/reference/exceptions.rst +++ b/reference/exceptions.rst @@ -1,6 +1,7 @@ Throwing Exceptions =================== -When you throw an exception using the Phalcon API, the current flow of execution will be stopped, returning to the last PHP code block when a Phalcon method where called. +When you throw an exception using the Phalcon API, the current flow of execution will be stopped, returning +to the last PHP code block when a Phalcon method where called. There are two ways to throw exceptions, the first, when the exception object only receives a string as parameter: diff --git a/reference/functions.rst b/reference/functions.rst index 53191ca..3085aac 100644 --- a/reference/functions.rst +++ b/reference/functions.rst @@ -9,7 +9,8 @@ Calling functions is another common action we do when create programs in PHP. Al PHALCON_INIT_VAR(length); PHALCON_CALL_FUNC_PARAMS_1(length, "strlen", some_variable); -The macro PHALCON_CALL_FUNC_PARAMS_1 calls functions that requires 1 parameter returning a value. There are another macros to call functions in the PHP userland: +The macro PHALCON_CALL_FUNC_PARAMS_1 calls functions that requires 1 parameter returning a value. There are another +macros to call functions in the PHP userland: .. code-block:: c @@ -23,9 +24,13 @@ The macro PHALCON_CALL_FUNC_PARAMS_1 calls functions that requires 1 parameter r //Closing a file with fclose PHALCON_CALL_FUNC_PARAMS_1_NORETURN("fclose", file_handler); -As mentioned above, PHP already has many things going, the fact that an extension in C, does not mean we going to reinvent the wheel all over again develop. Also worth saying that we also try to avoid using very low-level features of C, if PHP already has its own version. PHP functions help us get a behavior similar to that programming in the PHP would. In this way we avoid possible errors and as result the framework works as if it were PHP. +As mentioned above, PHP already has many things going, the fact that an extension in C, does not mean we going to +reinvent the wheel all over again develop. Also worth saying that we also try to avoid using very low-level +features of C, if PHP already has its own version. PHP functions help us get a behavior similar to that +programming in the PHP would. In this way we avoid possible errors and as result the framework works as if it were PHP. -The following code opens a file in C and write something on it. Its functionality is limited because it only works on local files: +The following code opens a file in C and write something on it. Its functionality is limited because it only works on +local files: .. code-block:: c @@ -56,7 +61,9 @@ Now write the same code using the PHP userland: PHALCON_CALL_FUNC_PARAMS_1_NORETURN("fclose", file_handler); } -Although both codes perform the same task, the former is more powerful as it could open a PHP stream, a file in a URL or a local file.We can also write the same code using the PHP API, without losing functionality. However the above code is more familiar if we are primarily PHP developers. +Although both codes perform the same task, the former is more powerful as it could open a PHP stream, a file in a URL + or a local file. We can also write the same code using the PHP API, without losing functionality. However, the + above code is more familiar if we are primarily PHP developers. The same code in PHP: diff --git a/reference/intro.rst b/reference/intro.rst index d937a81..e6b89c3 100644 --- a/reference/intro.rst +++ b/reference/intro.rst @@ -1,11 +1,13 @@ General Considerations ====================== -Phalcon is a C extension for PHP developers. The way in which Phalcon is written is not the usual, if you compare the code of Phalcon with other C extensions you'll see a huge difference, this unusual way of write the extension has several objectives: +Phalcon is a C extension for PHP developers. The way in which Phalcon is written is not the usual, if you compare +the code of Phalcon with other C extensions you will see a considerable difference, this unusual way of write +the extension has several objectives: * Provide a code that is closer to be understood by developers PHP * Create objects and components that act as close as possible to PHP objects * Avoid dealing with low-level issues, whenever possible -* Help to maintain a large base code like the Phalcon one +* Help maintain a large base code like the Phalcon one When writing code for Phalcon try to follow these guidelines: diff --git a/reference/memory.rst b/reference/memory.rst index 1f2b615..67498a1 100644 --- a/reference/memory.rst +++ b/reference/memory.rst @@ -1,12 +1,15 @@ Memory Management ================= -As you may know, the memory management in C is all manual. Within a PHP extension, all memory is managed by Zend Memory Manager, however the management remains manual. +As you may know, the memory management in C is all manual. Within a PHP extension, all memory is managed by +Zend Memory Manager, however, the management remains manual. -Manual memory management is a powerful tool that offers C. But, as PHP developers we are not used to this sort of thing. We like to just leave this task to the languag without worrying about it. +Manual memory management is a powerful tool that C offers. But, as PHP developers we are not used to this +sort of thing. We like to just leave this task to the language without worrying about that. Phalcon MM ---------- -To help in the creation of Phalcon, we have created the Phalcon Memory Manager (Phalcon MM) that basically tracks every variable allocated in order to free it before exit the active method: +To help in the creation of Phalcon, we have created the Phalcon Memory Manager (Phalcon MM) that basically +tracks every variable allocated in order to free it before exit the active method: For example: @@ -26,13 +29,18 @@ For example: PHALCON_MM_RESTORE(); } -PHALCON_MM_GROW starts a memory frame in the memory manager, then PHALCON_INIT_VAR allocates memory for the variable greeting, before exit the method we call PHALCON_MM_RESTORE, this releases all the memory allocated from the last call to PHALCON_MM_GROW. +PHALCON_MM_GROW starts a memory frame in the memory manager, then PHALCON_INIT_VAR allocates memory for the +variable greeting, before exit the method we call PHALCON_MM_RESTORE, this releases all the memory allocated +from the last call to PHALCON_MM_GROW. -By this way, we can be sure that all the memory allocated will be freed, avoiding memory leaks. Let's pretend that we used 10-15 variables, releasing manually the memory of them can be tedious. +By this way, we can be sure that all the memory allocated will be freed, avoiding memory leaks. Let's pretend +that we used 10-15 variables, releasing manually the memory of them can be tedious. Others Kinds of Allocations --------------------------- -PHALCON_INIT_VAR only allocates memory for zvals, if we want to request memory for other structures then we must use the functions that provides the Zend API. One very important thing to know is that an extension in C must never use the standard functions malloc and free. The Zend API has its own functions that make the memory access safer. +PHALCON_INIT_VAR only allocates memory for zvals, if we want to request memory for other structures then we must use +the functions that provides the Zend API. One very important thing to know is that an extension in C must never +use the standard functions malloc and free. The Zend API has its own functions that make the memory access safer. .. code-block:: c diff --git a/reference/methods.rst b/reference/methods.rst index a43a46d..8234328 100644 --- a/reference/methods.rst +++ b/reference/methods.rst @@ -1,6 +1,9 @@ Calling Methods =============== -As seen when calling functions, in Phalcon the methods are called in the PHP userland. Thanks to this, a Phalcon user can generate a backtrace and know exactly which components are involved in a given task. Additionally, like everything else we've seen, the way to make calls is familiar to PHP developers. +As seen when calling functions, in Phalcon the methods are called in the PHP userland. Thanks to this, a Phalcon +user can generate a backtrace and know exactly which components are involved in a given task. They also +allows users to replace Phalcon components by PHP classes of their own. Additionally, +like everything else we've seen, the way to make calls is familiar to PHP developers. Instance methods ---------------- @@ -17,7 +20,7 @@ Instance methods //Create a PDO instance passing the dsn to the constructor PHALCON_INIT_VAR(pdo); object_init_ex(pdo, pdo_class_entry); - PHALCON_CALL_METHOD_PARAMS_1_NORETURN(pdo, "__construct", dsn, PH_CHECK); + PHALCON_CALL_METHOD_PARAMS_1_NORETURN(pdo, "__construct", dsn); //Create a SQL statement PHALCON_INIT_VAR(sql_statement); @@ -25,7 +28,7 @@ Instance methods //Call the "exec" method in the pdo object passing the sql_statement PHALCON_INIT_VAR(success); - PHALCON_CALL_METHOD_PARAMS_1(success, pdo, "exec", sql_statement, PH_NO_CHECK); + PHALCON_CALL_METHOD_PARAMS_1(success, pdo, "exec", sql_statement); Static methods -------------- diff --git a/reference/objects.rst b/reference/objects.rst index 8b3e196..c6ef893 100644 --- a/reference/objects.rst +++ b/reference/objects.rst @@ -1,6 +1,7 @@ Objects Manipulation ==================== -Phalcon is a pure object oriented OO framework for PHP. In this chapter, we explain how to make most common operations on objects using the Phalcon API. +Phalcon is a pure object-oriented framework for PHP. In this chapter, we explain how to make most common operations +on objects using the Phalcon API. Creation/Instantiation ---------------------- @@ -15,7 +16,7 @@ Instantiate objects of the framework classes is easy: //Calling the constructor and passing a pattern as parameter PHALCON_INIT_VAR(pattern); ZVAL_STRING(pattern, "#^/([a-zA-Z0-9\\_]+)[/]{0,1}$#", 1); - PHALCON_CALL_METHOD_PARAMS_1_NORETURN(route, "__construct", pattern, PH_CHECK); + PHALCON_CALL_METHOD_PARAMS_1_NORETURN(route, "__construct", pattern); The above code is the same as doing in PHP: @@ -37,7 +38,7 @@ Moreover, if is not a Phalcon class then objects must then initialized as follow object_init_ex(reflection, reflection_ce); //Pass a class name as constructor's parameter - PHALCON_CALL_METHOD_PARAMS_1_NORETURN(reflection, "__construct", class_name, PH_CHECK); + PHALCON_CALL_METHOD_PARAMS_1_NORETURN(reflection, "__construct", class_name); Reading/Writing Properties -------------------------- diff --git a/reference/operations.rst b/reference/operations.rst index 6a1e9f0..51d4287 100644 --- a/reference/operations.rst +++ b/reference/operations.rst @@ -1,6 +1,7 @@ Operations between Variables ============================ -PHP is a dynamic language, we can do almost any operation between two variables, regardless of type. Sometimes we do not know exactly the type of data that have the variables, using the Zend API we can do operations between them seamlessly: +PHP is a dynamic language, we can do almost any operation between two variables, regardless of type. Sometimes we do +not know exactly the type of data that have the variables, using the Zend API we can do operations between them seamlessly: .. code-block:: c @@ -18,7 +19,8 @@ PHP is a dynamic language, we can do almost any operation between two variables, Concatenation ------------- -Concatenation is one of the most common operations we do in PHP. However using the Zend API can be tedious when concatenate many values​​, for example: +Concatenation is one of the most common operations we do in PHP. However, using the Zend API can be tedious when +oncatenating many values​​, for example: .. code-block:: c diff --git a/reference/phalcon-api.rst b/reference/phalcon-api.rst index 6e63eee..532faa7 100644 --- a/reference/phalcon-api.rst +++ b/reference/phalcon-api.rst @@ -1,9 +1,16 @@ Phalcon API ----------- -We, the creators of Phalcon, are mainly PHP programmers, we are lazy and do not want to deal 100% of the time with low-level details like segmentation faults or memory leaks. We believe that PHP language is incredible, and Phalcon is a contribution to all those things we do every day and it could be faster. +We the creators of Phalcon, are mainly PHP programmers, we are lazy and do not want to deal 100% of the time with +low-level details like segmentation faults or memory leaks. We believe that PHP language is incredible, and +Phalcon is a contribution to all those things we do every day and it could be faster. -Moreover we want a fast and stable framework. For this reason we have created the Phalcon API. The use of this API helps us to write C code in a PHP style. We have developed a number of functions to help the programmer to write code more interoperable with PHP in a easier way. +Moreover we want a fast and stable framework. For this reason, we have created the Phalcon API. The use of this +API helps us to write C code in a PHP style. We have developed a number of functions to help the programmer +to write code more interoperable with PHP in an easier way. -Phalcon API is based on the Zend API, but we have added more features to facilitate us the work. Phalcon is a very large project, frameworks need to be developed and improved every day, Phalcon API helps us to write C code that is more stable and familiar to PHP developers. +Phalcon API is based on the Zend API, but we have added more features to facilitate us the work. Phalcon is a +very large project, frameworks need to be developed and improved every day, Phalcon API helps us write C +code that is more stable and familiar to PHP developers. -If you're a PHP developer maybe you don't know C or you don't want to learn C, but after read this guide you will find the Phalcon API very familiar to your knowledge. \ No newline at end of file +If you're a PHP developer maybe you don't know C or you don't want to learn C, but after reading this guide you +will find the Phalcon API very familiar to your knowledge. \ No newline at end of file diff --git a/reference/structures.rst b/reference/structures.rst index 0cd4204..31e6fab 100644 --- a/reference/structures.rst +++ b/reference/structures.rst @@ -1,11 +1,16 @@ Common Structures ----------------- -To start explaining Phalcon, is neccesary to understand a couple of low level structures that are commonly used in the framework: +To start explaining Phalcon, is necessary to understand a couple of low-level structures that are commonly used in +the framework: Zvals ^^^^^ -Most variables used in the framework are Zvals. Each value within a PHP application is a zval. The Zvals are polymorphic structures, ie a zval can have any value (string, long, double, array, etc.). Inspecting some code you will see that most variables are declared Zvals. PHP has scalar data types (string, null, bool, long and double) and non-scalar data types (arrays and objects). There is a way to assign a value the zval according to the data type: +Most variables used in the framework are Zvals. Each value within a PHP application is a zval. The +Zvals are polymorphic structures, i.e. a zval can have any value (string, long, double, array, etc.). +Inspecting some code you will see that most variables are declared Zvals. PHP has scalar data types +(string, null, bool, long and double) and non-scalar data types (arrays and objects). There is a way +to assign a value the zval according to the data type: .. code-block:: c @@ -47,7 +52,8 @@ This is the internal structure of a zval: zend_uchar is_ref__gc; }; -Most of the time you will not have to deal directly accessing the internal structure of a zval. Instead the Zend API offers a comfortable syntax for altering its value or get information from it. +Most of the time you will not have to deal directly accessing the internal structure of a zval. Instead, the Zend API +offers a comfortable syntax for altering its value or get information from it. Previously we saw how to change their values ​​change according to the type, let's see how to read their values​​: @@ -70,8 +76,8 @@ If we want to know the data type of a zval: Zend Class Entries ^^^^^^^^^^^^^^^^^^ -Another common structure we used is the zend class entry. Every class in the C internal world has its own zend class entry. -That structure help us to describe a class, its name, method, default properties, etc. +Another common structure we used is the zend class entry. Every class in the C internal world has its own +zend class entry. That structure help us describe a class, its name, method, default properties, etc. .. code-block:: c diff --git a/reference/variables.rst b/reference/variables.rst index 1b3d9de..e59d7da 100644 --- a/reference/variables.rst +++ b/reference/variables.rst @@ -3,7 +3,9 @@ Variables Creation -------- -Unlike PHP, each variable in C must be declared at the beginning of the function in which we are working. Also, as noted above, all variables must be initialized before use. Even, it should be reset again when we change its value, for example: +Unlike PHP, each variable in C must be declared at the beginning of the function in which we are working. Also, +as noted above, all variables must be initialized before the use. Even, it should be reset again when we change its +value, for example: .. code-block:: c @@ -15,14 +17,16 @@ Unlike PHP, each variable in C must be declared at the beginning of the function ZVAL_STRING(some_number, "one hundred", 1); //Reinitialize the variable and change its value to long - PHALCON_INIT_VAR(some_number); + PHALCON_INIT_NVAR(some_number); ZVAL_LONG(some_number, 100); -When declaring the variables is important to initialize them to NULL. By doing this, PHALCON_INIT_VAR will know if the variable needs memory or it already have memory allocated. +If a variable is assigned within a cycle or it's re-assigned is important to initialize it to NULL in its declaration. +By doing this, PHALCON_INIT_NVAR will know if the variable needs memory or it already have memory allocated. Copy-on-Write ------------- -All the zval variables that we use in Phalcon are pointers. Each pointer points to its value in memory. Two pointers may eventually point to the same value in memory: +All the zval variables that we use in Phalcon are pointers. Each pointer points to its value in memory. Two pointers +may eventually point to the same value in memory: .. code-block:: c @@ -147,4 +151,4 @@ With Phalcon API we should not worry about this: PHALCON_INIT_VAR(b); ZVAL_LONG(b, 18); -Copying variables using PHALCON_CPY_WRT, we leave the task to Phalcon API of caring about the reference counting without worrying us about it. \ No newline at end of file +Copying variables using PHALCON_CPY_WRT, we leave the task to Phalcon API of caring about the reference counting without worrying us about that. \ No newline at end of file