php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #6156 Object loosing an array property
Submitted: 2000-08-14 16:11 UTC Modified: 2000-09-26 22:12 UTC
From: tite at wolstudios dot com Assigned:
Status: Closed Package: *General Issues
PHP Version: 4.0.1 OS: SuSe 6.4
Private report: No CVE-ID: None
 [2000-08-14 16:11 UTC] tite at wolstudios dot com
Hello.

I am using php 4.0.1 with Apache 1.3.12, I have a problem in
my php script with a bidimensional array that gets lost.

My script reads an html template from a file. The neat part
of it is that it supports nested loops in the templates to
be able to nest results from querys.

Source code is at:
 - start :
 http://212.85.33.69/~tite/cvs/burladero/encuestas.phps 
 - template engine:
 http://212.85.33.69/~tite/cvs/burladero/func_plant.phps
 - db engine : 
 http://212.85.33.69/~tite/cvs/burladero/db.inc.phps
 - Template :
 http://212.85.33.69/~tite/cvs/burladero/plts/res.tite

Executable:
http://212.85.33.69/~tite/cvs/burladero/encuestas.php?INIT=1&ID=16

To do so I read the template and make a tree structure with
objects bucle. While I read the template I create the tree.
There is no problem doing that. If you see the source code,
there is a function called salida() that just does an echo.
Through those outputs I check that the objects is filled up
propperly, even the propperty tablas which has a bidimensional array with a table name at position 0 and field names at the rest of positions.

Once filled up the memory, I use the function scanner to go through all the objects, make que querys to the mysql, and mix data and template.

My problem is that when I get to the next element to the root object ($raiz) I have all propperties set up, but the
bidimensional array tablas. Which when I checked at undo_where() and datos_db() it was ok, along with the rest
of the propperies of the object.

If you need some more information, please don?t doubt to contact me.

Thank You
Josafat Moragrega Fernandez
tite@wolstudios.com

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-08-15 07:17 UTC] stas@php.net
Could you please produce the short reproducing code of what doesn't work?
 [2000-08-15 13:31 UTC] tite at wolstudios dot com
I guess you mean an explanation of the algorith with code explanations. If it is not enough... just tell me.
func_plant starts at motor_plantilla, where $planti is the file name of our template. It creates a new instance of bucle and fills out some properties. Once done this, it calls lector_plantilla, that is supposed to read that file contained now in $Plantilla which is a global variable.

lector_plantilla will read that file and fill the instance of bucle that recieves with every line of the fille (property lineas). Before asigning it to the object, the line is parsed callin parser(). 

parser() will return untouched the lines that have no template tags (this means text contained between @% and %@). Our tags contains @%command:params%@. If it finds a tag, it will call the function asigned in $parser_func for that command with 2 params, the object bucle and the params that the tag had. 

in datos_db() and load_img() the array property of the bucle object gets filled with the values in params. $params contains table_name.field_name. As you can see by the salida() function, the object got filled propperly :

salida("a?adido $tabla $campo en while de ".$oBucle->tabla."<bR>\n");
salida("resultao[0][0] = ".$oBucle->tablas[0][0]."<BR>\n");
salida("ya tenemos ".sizeof($oBucle->tablas)." tablas <BR>\n");

output:
a?adido Maestro_respuestas nombre en while de Preguntas
resultao[0][0] = Preguntas
ya tenemos 2 tablas 

So, the object gets filled propperly. Once done this, it returns same thing with a w in front. The sense of doing this, is to have all field names and tables whenever the function scanner() is called, so this function will make a query to the mysql with those fields on the select part.

in do_where() a new instance of bucle is created hanging from the current instance. This new instance is linked to the parent instance through the propperty bucle->padre. Once done this, the lector_plantilla() is called up again so the lines contained between this @%where:...%@ and the following @%end-where:...%@ are assigned to this new instance of bucle. After this is done, the string @%wwhere:...%@ is returned to be assigned as a new line of the father instance so when scanner gets to it knows that it has to jump to a son instance and keep on parsing the son's lines before finishing these lines.

scanner() will go over all the memory nested of instances of bucle (after doing the query with the fields contained in bucle->tablas) and re-parse it. The different thing this time is that the tags (@% %@) will be replaced by the value  in the DB that corresponds to it. 

wdo_where() is called when the parser detects a wdb: tag. This function has to call scanner with the next son instance, so those lines get parsed before the lines from the actual instance gets parsed.

My problem is that when scanner() is called this second time from wdo_where() with the son's instance. The son's instance lost the array property tablas, but it didnt loose any other propperty value. 

I don?t know if this explanation satisfied your request, I hope so. If there are still doubts, contact me.

Thank you in advance.

Josafat Moragrega Fernandez
 [2000-08-28 10:34 UTC] tite at wolstudios dot com
Hello Again.

I reduced the code, and issued many outputs in my script to make it cleaner for everybody to understand. The script source is at http://212.85.33.69/~tite/cvs/burladero/rep/func_plant.phps, also you can check the execution on http://212.85.33.69/~tite/cvs/burladero/rep/func_plant.php .

The array $Plantillas is what it is beeing processed each time. You will be able to follow the execution of the code with the output, as well as to see what its being done.

At the end there is a Result display which clearly shows that those values were lost.

Again, if you have any doubts, dont hesetate to contact me.

Best Regards

Josafat Moragrega
 [2000-08-28 17:06 UTC] waldschrott@php.net
Short reproducing code = <25 lines of code whith all
unnecessary stuff (db-calls,comments etc. etc.) removed.
We cannot help you solving errors in yours scripts, but if
you think it?s a scripting engine error, reduce your script
much more and paste the result here...
again, reduce your code as much as possible, cut off arrays
to contain less elements and so on as long as that buggy
behaviour stays...
 [2000-09-25 19:03 UTC] stas@php.net
Code is too big to be comprehendable.
Please:
1. Check latest version to see if the error still there
2. Reduce it to the minimal example reproducing the behaviour (I have yet to see a bug that cannot be reproduced in one-page code).
 [2000-09-25 20:57 UTC] tite at wolstudios dot com
Hello again.

I am sorry for the lateness answering the message. Last week
I found the bug. I asigned one of the objects of the tree from what it was a local var (which I thought it was not) using &, so the following branches from the tree disappeared when the recursive function returned all the way. 

I am sorry, I was the bug ;) Thank you all for your time. Next time I'd have to send a report Ill send it directly in less than 25 lines.

Best Regards

Josafat Moragrega Fernandez
tite@wolstudios.com
www.wolstudios.com
 [2000-09-26 22:12 UTC] sniper@php.net
Problem solved -> closed.

--Jani
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 06 01:01:31 2024 UTC