What's wrong?

posted by kalprestito on 2010-01-05 13:40:19
What's wrong? Someone can help me, please? Thanks.
It's a code of an art website. The error seems to be in the line 88 (Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in xxx/inc/class.Cuadro.php on line 88). I'm using the last version of Xampp over Mac.
 
<?php
//requiring some files
class Picture {
//Declaration of private variables
        private $_id;
	private $_nombre;
	private $_descripcion;
	private $_descripcioncorta;
	private $_imagen;
	private $_precio;
	private $_changed = false;
//from here, it searches a 'free' id in the entries' folder. if there is a 4.php and the next file is 6.php it creates 5.php and puts there the entry (this project is over files, not over db) and if readdir() completes all the dir it creates a new id. I also jumped the _get and _set.
	public function _destruct () {
		if ($this->_changed) {
			$this->save($this);
		}
	}
//Here is the error
	public function save () {
		$file = fopen ($cuadrospath.$this->_id.".php", "w"); //it opens a stream
		if (!is_null($this->_imagen)) { //if there is an image object
			<b>$img = "$cuadro[\"" . $this->_id . "\"][\"imagen\"] = new Imagen (\"" . $this->_imagen->_url . "\");\n"; //is now when php detects an error (??) here it creates a string for writing it in a file</b>
		}else{
			$img = ""; //else it doesn't say anything
		}
		$flcont = "<?php //it builds all the pieces. i removed the first error (removing that part) but it says me the same error here
require_once ($incpath.\"class.Imagen.php\");
$cuadro[\"" . $this->_id . "\"][\"nombre\"] = " . $this->_nombre . ";
$cuadro[\"" . $this->_id . "\"][\"descripcion\"] = " . $this->_descripcion . ";
$cuadro[\"" . $this->_id . "\"][\"descripcioncorta\"] = " . $this->_descripcioncorta . ";
" . $img . "$cuadro[\"" . $this->_id . "\"][\"precio\"] = " . $this->_precio . ";
?>";
		fwrite ($file, $flcont);//writes
	}
}
?> //and exit
 
kalprestito
0
I've found the error. PHP recognised $cuadro like a variable into a text instead writing "$cuadro" literally. To solve this:
 
(...)
$var = "$";
(...)
$img = $var . "cuadro"; //now works!!!
(...)
 
4 answers - 3 questions
  Positive      - 1  Negative

livin52 avatar
livin52
3
Rewrite that line with this:
 
     $img = '$cuadro["' . $this->_id . '"]["imagen"] = new Imagen ("' . $this->_imagen->_url . '");\n';
 
Now it should work... The problems was the "
" at the beginning of the line. And there was another problem (like kalprestito said) in the string regarding a $cuadro variable.
Saludos!
6 answers - 0 questions
  Positive        Negative

kalprestito
0
That isn't a Problem 'cause PHP recognizes "
" as a "\n" symbol.
:-( But good trying!!
As I said Formerly, was the $ symbol.
4 answers - 3 questions
  Positive        Negative



Answer the question



Top Users
  • dail (12)
  • livin52 (3)
  • camu (3)
  • softweb (2)
  • Nadine (1)
  • Josware (1)
  • lfelipecr (1)
  • gregoriohc (1)
  • Mitu (1)
  • ryan714 (1)