Code Corner -> Wrong Syntax?

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

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 …

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 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.

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
Outdoor Unlimited Training GmbH [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 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=/


eGroupWare-developers mailing list
eGroupWare-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/egroupware-developers

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

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