Pass by reference
  > Home
v User Guide
    > Introduction
    > Hello World
    > Flow Control
    v Function Calls
       o Arguments
       o Argument list
       o Absolute arguments
       o Results
       o Context linking
       o Pass by reference
    > Authentication
    > Database access
    > Content Management
    > Remote Calling
    > Object-Oriented
    > Other Features
> Reference
> Portal Object
> Development Guide

sys Class
debug Class
Intrinsic Conversions
>> User Guide >> Function Calls >> Pass by reference <=  =>      <  1  >  
Pass by reference

Arguments are passed by value only (even with the "(var)" type cast).  There is no intrinsic implementation in BEE for arguments passing by reference.

However, you can still pass arguments by reference by passing the variable name instead, and linking the variable to the parent context from inside the function.  That way, changes made to the argument variable will survive the function exit because it is the linked parent variable that was changed..

In the following example, the variable name is in arg%x, and therefore the variable is indicated by {arg%x} and its element {arg%x}:key.  (Also, the loop variable "foreach" is a copy of the loop source value, not the loop source element itself.  To change the loop source, you need to explicitly assign a value to it.)

function addone {

   if ({arg%x|isset} == 0 || {#arg%x:} == 0) return;


   parent {arg%x};

   foreach ({arg%x}) var {arg%x}:{foreach:key} conv=++;

   var result%function = "(var){arg%x}";



var myArr = "(array)a=>1,b=>2,c=>3";

display "Before: {myArr|list}<br>\n"; // Output: Before: a=>'1',b=>'2',c=>'3'

addone x="myArr";

display "After: {myArr|list}<br>\n";  // Output: After: a=>'2',b=>'3',c=>'4'

display "Result is {result%addone|list}<br>\n";


(The string {arg%x}:{foreach:key} indicates the variable name.  It evaluate to a variable name in the parent context (since we have parent {arg%x}).  There is no need to quote a string in BEE unless it has white spaces in it.  If you feel uncomfortable about the syntax, you can use var "{arg%x}:{foreach:key}" conv="++"; instead).


Previous Page       Next Page

Accsoft Computer Technology Pty Ltd     ABN: 98 065 617 549
PO Box 892, Epping NSW 1710         Level 1, Epping Office Park, 242 Beecroft Rd, Epping NSW 2121, Australia
Tel: Sydney - (02)98691668     National - 1300-881668         Fax: (02)98691866
© Copyright 2003 Accsoft Computer Technology Pty Ltd