Error Parsing internal libraries class

I have created a class call Audition.php in internal libraries and when I try to pull record on grid onRecord event it throws an error
Parse error: syntax error, unexpected ‘{’ in C:\Program Files (x86)\NetMake\v81\wwwroot\scriptcase\app\LSC_data\grid_j3x_sdirectories_members\Audition.php on line 19
// Class Audition
<?php
class Audition{
protected $genre;
protected $id;

public function __construct($genre, $id) {
      $this-&gt;genre = $genre;
    $this-&gt;id = $id;
    }

public function getMarks(){
    
    $check_sql = "SELECT marks"
       . " FROM j3x_sdirectories_auditions"
       . " WHERE profile_id ='".$this-&gt;id ."' AND genre ='".$this-&gt;genre."'";
    sc_lookup(rs, $check_sql);
    
    if(isset({rs[0][0]})){
        
        return $marks = {rs[0][0]};
        
        }
    else {
        return $marks = '';
        }

    }
}

?>

//Method called in onRecord event in grid application

$b_g =1;
$id = {id};

$ballet = new Audition($b_g, $id);

{Ballet} = $ballet->getMarks();

anyone can tell me where it went wrong?

From a fast look at your code, I think that the problem in line 19 is that you refer to the dataset rs with {res[0][0]}:

a. Should it not be {rs}[0][0]

b. Can you even refer to ScriptCase variables using {} notation inside internal libraries. I would think that $ds[0][0] would be better

c. I would also think that sc_lookup, a ScriptCase macro, could not be used inside inside internal libraries – at least that used to be the case. If so, you have to separate concerns and make sure that your PHP class only uses pure PHP. You can pass it a dataset and other variables, but refer to them with $var notation and do not use ScriptCase macros inside the class.

  1. Recommended way is {rs[][]}.

  2. You can, parser changes it for you, but yes, its good idea to use it the way you mention.

  3. You can use macros on internal libs, but not on external libs.

Internal libs are not friends of OOP. I don’t recommend to use internal libs as placeholders for classes. Just use functions there. Just my opinion.

@Giu, thanks!
I stand corrected. Clearly, they have improved functionality in the internal libraries in the latest version.

I wonder what the problem with Naresh’s code is then.

Not sure. Maybe the problem comes based on your assumption. I don’t look into code don’t formatted. maybe, if he changes

if(isset({rs[0][0]})){

for

if(isset($rs[0][0])){

Could be a solution, or the problem maybe it’s the class itself. I don’t see it right now.

I would empty this file and just have:

public function getMarks($genre, $profileid){

$check_sql = "SELECT marks"
. " FROM j3x_sdirectories_auditions"
. " WHERE profile_id ='".$profileid ."' AND genre ='".$genre."'";
sc_lookup(rs, $check_sql);

if(isset($rs[0][0])){

return $marks = {rs[0][0]};

}
else {
return $marks = '';
}

And call this function with params. Class is not needed in this situation, and is not a good idea using on internal libs. They need to fit a lot of criterias to work. It’s not worth.

Thank you all for your reply,

Does SC supports OOP libraries? if I use them externally? I understand to use only method in internal libraries. However, I used the function bellow on one of an events of an application it works

function getMarks($genre, $id){
$check_sql = "SELECT marks"
. " FROM j3x_sdirectories_auditions"
. " WHERE profile_id ='".$id ."' AND genre ='".$genre."'";
sc_lookup(rs, $check_sql);
if (isset({rs[0][0]})){
return $marks = {rs[0][0]};


}
else {

return $marks ='';
}

}

If I could use this function in one of a class it would a massive amount of time. I realise SC macros are not recognize by external libraries.

It would be really helpful if we could create on macros and use as sc_macros.

I have used simpler classes in internal libraries without any problems, although it has been pure PHP code without any sc_macros or {} references. However, I think its worth a try.

I did try yesterday to define a simple internal library function that used { } form field references and set the value of a global variable [ ] as well use a class defined in another internal library. That did not work at all. I had to instead copy the function code directly into each code section of the form after which the code could reference the internal library class without any problems.

As for OOP libraries the new external library function should be fine: http://www.scriptcase.net/docs/en_us/v81/manual_mp.htm#tools/libraries

Thanks this seems to be helpful.

External libraries are not parsed by SC parser. For this reason macros don’t works there, just “standard” php. SC is a declarative closed environment, don’t like to have friends like OOP, TDD and so on… :slight_smile:

At scriptcase 9.xxxx same problem.
Any solution ?