Page 1 of 1

A Bug? .. $dataTable->Rows->Add($newRow) .. no working.

PostPosted: May 31st, 2011, 8:56 am
by kielsoft

Seem there is a problem somewhere, don't know if its a bug, when converting the c# code on this page to phalanger PHP works differently from the normal expected output.

http://msdn.microsoft.com/en-us/library/system.data.datatable.newrow.aspx


Pls what is what do you think its wrong with
$datatable->rows->add($row);

$row is an object (I.e DataRow class ) and when I useadd() method,  it adds it like a string and will show 'System.Data.DataRow' in theDataGridView ....


RE: A Bug? .. $dataTable->Rows->Add($newRow) .. no working.

PostPosted: May 31st, 2011, 8:44 pm
by kielsoft

Method Invocation
Dynamic methods are generated at runtime also for methods invoked on CLR types. The PHP
language does not support method overloading and there is currently no way how to provide a hint
for the compiler as to in which overload the user is interested. Thus the principal task of a stub is to
choose the most appropriate overload of the target method based on the number and types of the
supplied actual arguments.
Each stub contains a switch which essentially filters out overloads with the number of formal
parameters that is smaller or greater than the number of actual arguments supplied to the call.
Afterwards, the overloads with the correct number of parameters are tested one-by-one by trying to
convert arguments to their parameter types. The first overload, for which all arguments are
convertible to its parameter types, receives the invocation. The conversions must constitute a
sensible trade-off between dynamism and selectivity. PHP can convert any type to just about any
other type but if the conversion routines behaved like this, inappropriate overloads would have been
called. For instance, every object in PHP is implicitly convertible to a number, which yields either 0 or
1 depending on whether there are any fields in the object. The conversion routines involved in
overload resolution must suppress these heavy-weight conversions.
Phalanger fully supports calling methods with ref and out parameters, because PHP contains the
notion of by-reference argument passing. If an argument is about to be passed by reference, it is
pushed to the stack wrapped by a PhpReference. The value is unwrapped, converted to the
corresponding parameter type, stored to a local variable, and the address of the local is passed to the
target method. When the method returns, the (possibly updated) local is converted back to
Phalanger type and stored back to the PhpReference.
Methods with a params parameter, i.e. an array parameter decorated by the
ParamArrayAttribute, have slightly more complicated stubs. Consider the following set of
overloads.

void Foo();void Foo(int x1);void Foo(int x1, int x2);void Foo(int x1, int x2, int x3);void Foo(params object[] args);


The last params overload can become the most appropriate overload for every argument count
except for zero. The generated stub for this set of overloads has to consider it in every switch
branch because if the conversions to int fail, the last overload is a fallback. Moreover, there must
be a default case containing a loop, in which all actual arguments are converted to the params array.
Finally, the params overload can also be called by explicitly passing an array, so the switch branch
for exactly one argument on the stack contains the following.

POP arg1 from stack
IF arg1 is convertible to int, call the Foo(int) overload
ELSE IF arg1 is convertible to object, create new object[] { arg1 } and call the Foo(object[]) overload
ELSE IF arg1 is convertible to object[], call the Foo(object[]) overload
ELSE error


RE: A Bug? .. $dataTable->Rows->Add($newRow) .. no working.

PostPosted: May 31st, 2011, 8:51 pm
by kielsoft

Could this be my problem? I found that in "Phalanger: Integrating PHP with CLR" by  Ladislav Prošek, Tom áš M atoušek, Page 7 & 8.


Can someone please show me how to implement ..... 

POP arg1 from stack
IF arg1 is convertible to int, call the Foo(int) overload
ELSE IF arg1 is convertible to object, create new object[] { arg1 } and call the Foo(object[]) overload
ELSE IF arg1 is convertible to object[], call the Foo(object[]) overload
ELSE error


.....in PHP. 

I have tried this $datatable->rows->add((object) $row);  and it is not working.

Thanks.


RE: A Bug? .. $dataTable->Rows->Add($newRow) .. no working.

PostPosted: June 1st, 2011, 4:27 pm
by kielsoft

Please say something helpful.


RE: A Bug? .. $dataTable->Rows->Add($newRow) .. no working.

PostPosted: June 15th, 2011, 4:39 pm
by kielsoft

Can someone help with this and let me know is it's a bug or there is another way to do this? or if my code is needed I can mail it to you.


Re: A Bug? .. $dataTable->Rows->Add($newRow) .. no working.

PostPosted: January 4th, 2014, 7:36 am
by Leo123
$row is an object (I.e DataRow class ) and when I useadd() method, it adds it like a string and will show 'System.Data.DataRow' in theDataGridView ....