# Code Corner -\> Wrong Syntax?

**URL:** <http://discourse.egroupware.org/t/code-corner-wrong-syntax/26920>\
**Category:** eGW-developers\
**Created:** [September 18, 2008, 10:21am UTC](http://discourse.egroupware.org/t/code-corner-wrong-syntax/26920 "2008-09-18T10:21:48Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dr.Evil2k](http://discourse.egroupware.org/letter_avatar_proxy/v4/letter/d/b4bc9f/32.png) [@Dr.Evil2k](http://discourse.egroupware.org/u/Dr.Evil2k)\
**Post date:** [September 18, 2008, 10:21am UTC](http://discourse.egroupware.org/t/code-corner-wrong-syntax/26920/1 "2008-09-18T10:21:48Z")

</div>

Hello World,  
i’m trying to do the steps of the code corner (day 2). I copied the syntax shown there and made some adjustments to my own needs.

So the code for my class.uiajaxchat.inc.php is now:

_\<?php  
class uiajaxchat  
{  
var $public\_functions = array(  
‘ajaxchatinterface’ =\> True,  
);_

```
public function create_header ()
{
	$GLOBALS['egw']->common->egw_header();
	echo parse_navbar();

}

public function create_footer ()
{
	$GLOBALS['egw']->common->egw_footer();
}

function ajaxinterface ()
{
    $this->create_header();
    if (trim($_POST['fname'].$_POST['sname'])!='')
    {
        //echo ''.$_SERVER['PHP_SELF'].'<br>';
        echo "<br>Hello ".$_POST['fname']." ".$_POST['sname']."<br>";
        echo "<form action='".$GLOBALS['egw']->link('/index.php',array(
    'menuaction' => 'AjaxChat.uiajaxchat.ajaxchatinterface','message'=>'YES'))."' method='post'>
        <input type='submit' value=' Reload '>
        </form>";
    }
    else
    {
        echo "Type a name to be greeted accordingly <br>";
        echo "<form action='".$GLOBALS['egw']->link('/index.php',array(
    'menuaction' => 'AjaxChat.uiajaxchat.ajaxchatinterface','message'=>'NO'))."' method='post'>
          <p>first name:<br><input name='fname' type='text' size='30' maxlength='30'></p>
          <p>name:<br><input name='sname' type='text' size='30' maxlength='40'></p>
                <input type='submit' value=' Submit '>
                <input type='reset' value=' Cancel'>
        </form>";

    }
    $this->create_footer();
}

```

}

When i try to run the script i allways get the error:

_Parse error: syntax error, unexpected T\_STRING, expecting T\_OLD\_FUNCTION or T\_FUNCTION or T\_VAR or ‘}’ in /path\_to\_egw/AjaxChat/inc/class.uiajaxchat.inc.php on line 8_

So the problem is with the “public function” declaration…  
This error occured allready in the first steps of day two, so i just copy&paste this code and made my adjustments, hoping to get around them… but as you can see it didnt work.

I hope someone is able to help me. Thanks alot allready!  
Greetings - Eric

---

<div class="post-metadata">

**Author:** ![Leithoff\_Klaus](http://discourse.egroupware.org/letter_avatar_proxy/v4/letter/l/d07c76/32.png) [@Leithoff\_Klaus](http://discourse.egroupware.org/u/Leithoff_Klaus)\
**Post date:** [September 18, 2008, 11:14am UTC](http://discourse.egroupware.org/t/code-corner-wrong-syntax/26920/2 "2008-09-18T11:14:40Z")

</div>

If I take the content of your post, put that into a file and call it from  
somewhere  
$this-\>ajaxchat =& CreateObject(‘YOURAPP.uiajaxchat’);  
$this-\>ajaxchat-\>ajaxinterface();  
It works as expected for me …

---

<div class="post-metadata">

**Author:** ![Dr.Evil2k](http://discourse.egroupware.org/letter_avatar_proxy/v4/letter/d/b4bc9f/32.png) [@Dr.Evil2k](http://discourse.egroupware.org/u/Dr.Evil2k)\
**Post date:** [September 18, 2008, 11:39am UTC](http://discourse.egroupware.org/t/code-corner-wrong-syntax/26920/3 "2008-09-18T11:39:08Z")

</div>

Hey Klaus, thanks for the fast answer.  
I’m not sure if I did everything right, but i followed the steps of the code corner, so i have the /AjaxChat/index.php with the one line of code reffering to my class. I also have the class.uiajaxchat.inc.php as mentioned before.

Where do i have to put the lines you wrote?

Eric

> [@](#):
>
> If I take the content of your post, put that into a file and call it from  
> somewhere  
> $this-\>ajaxchat =& CreateObject(‘YOURAPP.uiajaxchat’);  
> $this-\>ajaxchat-\>ajaxinterface();  
> It works as expected for me …

---

<div class="post-metadata">

**Author:** ![Leithoff\_Klaus](http://discourse.egroupware.org/letter_avatar_proxy/v4/letter/l/d07c76/32.png) [@Leithoff\_Klaus](http://discourse.egroupware.org/u/Leithoff_Klaus)\
**Post date:** [September 18, 2008, 1:46pm UTC](http://discourse.egroupware.org/t/code-corner-wrong-syntax/26920/4 "2008-09-18T13:46:37Z")

</div>

If you have the index.php, with that one line of code, it does about the  
same  
as I did with the two lines to call that bit of code from somewhere else.  
The line with the CreateObject, does the class instanciation, and the  
line $this-\>ajaxchat-\>ajaxinterface(); just calls the function.

header(‘Location:  
…/index.php?menuaction=YOURAPP.uiajaxchat.ajaxinterface’);  
Does about the same, but somewhere else.

---

<div class="post-metadata">

**Author:** ![Ralf\_Becker\_6](http://discourse.egroupware.org/user_avatar/discourse.egroupware.org/ralf_becker_6/32/1306_2.png) [@Ralf\_Becker\_6](http://discourse.egroupware.org/u/Ralf_Becker_6)\
**Post date:** [September 19, 2008, 7:39am UTC](http://discourse.egroupware.org/t/code-corner-wrong-syntax/26920/5 "2008-09-19T07:39:53Z")

</div>

Just a guess, you use the php5 qualifier “public” on a php4 server

Ralf

Dr.Evil2k schrieb:

> Hello World,  
> i’m trying to do the steps of the code corner (day 2). I copied the syntax  
> shown there and made some adjustments to my own needs.
> 
> So the code for my class.uiajaxchat.inc.php is now:
> 
> \<?php class uiajaxchat { var $public\_functions = array( 'ajaxchatinterface' =\> True, ); public function create\_header () { $GLOBALS['egw']-\>common-\>egw\_header(); echo parse\_navbar(); } public function create\_footer () { $GLOBALS['egw']-\>common-\>egw\_footer(); } function ajaxinterface () { $this-\>create\_header(); if (trim($\_POST['fname'].$\_POST['sname'])!='') { //echo ''.$\_SERVER['PHP\_SELF'].'  
> '; echo "  
> Hello ".$\_POST['fname']." ".$\_POST['sname']."  
> "; echo "link('/index.php',array( 'menuaction' =\> 'AjaxChat.uiajaxchat.ajaxchatinterface','message'=\>'YES'))."' method='post'\> "; } else { echo "Type a name to be greeted accordingly   
> "; echo "link('/index.php',array( 'menuaction' =\> 'AjaxChat.uiajaxchat.ajaxchatinterface','message'=\>'NO'))."' method='post'\> 
> 
> first name:
> 
> name:
> 
> "; } $this-\>create\_footer(); } } When i try to run the script i allways get the error: Parse error: syntax error, unexpected T\_STRING, expecting T\_OLD\_FUNCTION or T\_FUNCTION or T\_VAR or '}' in /path\_to\_egw/AjaxChat/inc/class.uiajaxchat.inc.php on line 8 So the problem is with the "public function" declaration... This error occured allready in the first steps of day two, so i just copy&paste this code and made my adjustments, hoping to get around them... but as you can see it didnt work. I hope someone is able to help me. Thanks alot allready! Greetings - Eric

–  
Ralf Becker  
eGroupWare Training & Support ==\> [http://www.egroupware-support.de](http://www.egroupware-support.de)  
Outdoor Unlimited Training GmbH [[www.outdoor-training.de](http://www.outdoor-training.de)]  
Handelsregister HRB Kaiserslautern 3587  
Geschäftsführer Birgit und Ralf Becker  
Leibnizstr. 17, 67663 Kaiserslautern, Germany  
Telefon +49 (0)631 31657-0

* * *

This [SF.Net](http://SF.Net) email is sponsored by the Moblin Your Move Developer’s challenge  
Build the coolest Linux based applications with Moblin SDK & win great prizes  
Grand prize is a trip for two to an Open Source event anywhere in the world  
[http://moblin-contest.org/redirect.php?banner\_id=100&url=/](http://moblin-contest.org/redirect.php?banner_id=100&url=/)

* * *

eGroupWare-developers mailing list  
[eGroupWare-developers@lists.sourceforge.net](mailto:eGroupWare-developers@lists.sourceforge.net)  
[https://lists.sourceforge.net/lists/listinfo/egroupware-developers](https://lists.sourceforge.net/lists/listinfo/egroupware-developers)

---

<div class="post-metadata">

**Author:** ![Dr.Evil2k](http://discourse.egroupware.org/letter_avatar_proxy/v4/letter/d/b4bc9f/32.png) [@Dr.Evil2k](http://discourse.egroupware.org/u/Dr.Evil2k)\
**Post date:** [September 19, 2008, 7:50pm UTC](http://discourse.egroupware.org/t/code-corner-wrong-syntax/26920/6 "2008-09-19T19:50:36Z")

</div>

Oh damn, you’re right. But what can I do now? Is it possible to declare just a “function” and use it the same way as a “public function”. Can I still follow the steps of the Code Corner?

Thank you very much allready. You helped quite alot.

Eric

> [@](#):
>
> Just a guess, you use the php5 qualifier “public” on a php4 server
> 
> Ralf

---

<div class="post-metadata">

**Author:** ![Dr.Evil2k](http://discourse.egroupware.org/letter_avatar_proxy/v4/letter/d/b4bc9f/32.png) [@Dr.Evil2k](http://discourse.egroupware.org/u/Dr.Evil2k)\
**Post date:** [September 19, 2008, 8:20pm UTC](http://discourse.egroupware.org/t/code-corner-wrong-syntax/26920/7 "2008-09-19T20:20:10Z")

</div>

Ok, obviously it is possible to do so. 🙂  
I tried and it seems to work.
