TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 06-25-2009, 11:31 AM   #1 (permalink)
The Wanderer
 
Join Date: Jun 2009
Posts: 20
Thanks: 2
tech is on a distinguished road
Default PHP Parse error: parse error,syntex error unexpected ',' expectingT_STRING in my code

dear friend...
I have written one function in php first time and i got one error called parse error in line number 7.here i m trying to remove one value from an array.but m am not able to solve it.please solve this error..below is the code.
thanks...
function extract($this)
{
if($this->parent)
{
try
{

array_splice($parent->content->,$this);//here i can be remove from parent contents array.
}
catch(){}

}
$lastChild=$this->lastRecursiveChild();
$nextElement =$lastChild->next;

if($this->previous)
{
$this->previous->next=$nextElement;
}
if($nextElement)
{
$nextElement->previous=$this->previous;
}
$this->previous=null;
$lastChild->next = Null;
$this->parent = Null;
if ($this->previousSibling)
{
$this->previousSibling->nextSibling = $this->nextSibling;
}
if ($this->nextSibling)
{
$this->nextSibling->previousSibling = $this->previousSibling;
}
$this->previousSibling = $this->nextSibling = Null;
return $this;
}
tech is offline  
Reply With Quote
Old 06-25-2009, 11:42 AM   #2 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,215
Thanks: 90
Wildhoney is on a distinguished road
Default

It's because you're missing "Exception $e" in your catch statement. The $e variable will then contain the Exception object, and so you'll be able to get the messages from it, and error codes, etcetera.

php Code:
if($this->parent)
{
    try
    {
        array_splice($parent->content->,$this);
    }
    catch(Exception $e)
    {
       
    }
}

Incidentally, could you please prettify your pasted code in future. There's a better chance somebody will respond when they open a thread with nicely formatted and coloured code.

Help: Prettifying Pasted Code on TalkPHP
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 06-25-2009, 11:50 AM   #3 (permalink)
The Wanderer
 
Join Date: Jun 2009
Posts: 20
Thanks: 2
tech is on a distinguished road
Default

i have tried using Exception $e in catch block but same error is coming..
tech is offline  
Reply With Quote
Old 06-25-2009, 11:58 AM   #4 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 836
Thanks: 31
sketchMedia is on a distinguished road
Default

In addition to the catch block as mentioned, this line seems to be a culprit:

PHP Code:
array_splice($parent->content->,$this);//here i can be remove from parent contents array. 
should it be:
PHP Code:
array_splice($parent->content,$this);//here i can be remove from parent contents array. 
Just as a note, I would discourage anyone from using $this in any other context apart from within an object.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
The Following User Says Thank You to sketchMedia For This Useful Post:
tech (06-25-2009)
Old 06-25-2009, 12:09 PM   #5 (permalink)
The Wanderer
 
Join Date: Jun 2009
Posts: 20
Thanks: 2
tech is on a distinguished road
Default

thanks..I am corrected that one but now i m getting fatal error : cannot redeclare extract()on line number 39 that is ?>
tech is offline  
Reply With Quote
Old 06-25-2009, 12:14 PM   #6 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,215
Thanks: 90
Wildhoney is on a distinguished road
Default

There's already a function called extract in PHP, so you'll need to either rename it, or put it into a class (a namespace would be ideal).

Hopefully PHP's extract doesn't do the same as your extract.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 06-25-2009, 12:29 PM   #7 (permalink)
The Wanderer
 
Join Date: Jun 2009
Posts: 20
Thanks: 2
tech is on a distinguished road
Default

Thanks..for sharing a knowledge ..one more thing I wanted to know is : in a try block i am trying to remove an index from an array using array_splice.SO,it will work properly.
tech is offline  
Reply With Quote
Old 06-25-2009, 12:43 PM   #8 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,215
Thanks: 90
Wildhoney is on a distinguished road
Default

If you're wanting to remove one particular index from the array, then you could use the unset construct.

php Code:
$aFruit = array('Apples', 'Oranges', 'Bananas');

/* Remove "Oranges" */
unset($aFruit[1]);

/* Apples, Bananas */
echo implode(', ', $aFruit);
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 06-25-2009, 01:13 PM   #9 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 836
Thanks: 31
sketchMedia is on a distinguished road
Default

Something else that I have just noticed.
Your use of a try .. catch block won't work as expected.
The reason being that array_splice doesn't throw an Exception therefore nothing will get caught.
PHP doesn't use the try catch like JavaScript does, JavaScript's try .. catch block catches errors but PHP behaves much like Java and will only catch an Exception.

PHP Code:
try 
{
    throw new 
Exception('This is an exception');
}
catch(
Exception $e)
{
    echo 
$e->getMessage();

You can fudge PHP to throw an exception on error/notice etc by using set_error_handler
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 06-25-2009, 01:20 PM   #10 (permalink)
The Wanderer
 
Join Date: Jun 2009
Posts: 20
Thanks: 2
tech is on a distinguished road
Default

thank..can u please tell me what changes i can do at that place so it will work to my expectation.here i wanted to remove an object from an array.contents is an array and i wanted to remove current object from the array.
tech is offline  
Reply With Quote
Old 06-25-2009, 01:39 PM   #11 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,239
Thanks: 3
Salathe is on a distinguished road
Default

Can you explain more precisely what you are trying to do? Perhaps give some examples of how you would use the function, as currently you aren't being very clear and the code is making it difficult to work out what you're even trying to do.
__________________
salathe@php.net
Salathe is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
10 PHP Myths Dispelled Wildhoney General 10 06-15-2009 06:55 AM
how to parse source code of a webpage sarmenhb General 10 11-06-2008 04:19 PM
PHP Compressor Kalle Script Giveaway 8 05-28-2008 12:14 AM
Display pages php code? Aaron General 16 01-31-2008 10:29 AM
Writing Clean Code Village Idiot Tips & Tricks 5 01-09-2008 04:37 PM


All times are GMT. The time now is 05:46 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design