Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pchp.Library.Spl.TypeError: "A scalar of type 'double' used as an object" #1067

Closed
FibonacciFox opened this issue Sep 8, 2022 · 7 comments
Closed

Comments

@FibonacciFox
Copy link

FibonacciFox commented Sep 8, 2022

Hello, peachpie team!
I am working on creating a software development environment using peachpie. Faced with such a problem.

Creating a button click event in php

image

How is this implemented in c#
private readonly IDictionary<string, EventHandler<RoutedEventArgs>> _events;
image

Error:
image

1. This error occurs with any scalar type that I pass to an anonymous php function.
1.1.This error occurs only if an anonymous function is called in a c# event.

The Content property has the object type.

image
If you redefine the Content property in:
image
There will be no mistakes!

If the anonymous function is called as is, there will be no errors outside of events, the code works!
If you pass a parameter to an anonymous function and call it in an event, the error described above will occur!
It is impossible to bring it to the desired type, the error occurs at the stage of accessing the Content property
@FibonacciFox
Copy link
Author

FibonacciFox commented Sep 8, 2022

image

If you declare : $content = 123.1; inside an anonymous function, it will not cause errors. The Content property will be NULL

We see this behavior only when we call any event.

And redefining properties in the framework from the object type to PhpValue will be a very time-consuming process.

@jakubmisek
Copy link
Member

Hi @FibonacciFox !

Do you have a stack trace of the exception? I recommend also disabling "Just My Code" when debugging (depends on your IDE).

@FibonacciFox
Copy link
Author

FibonacciFox commented Sep 11, 2022

Hi @FibonacciFox !

Do you have a stack trace of the exception? I recommend also disabling "Just My Code" when debugging (depends on your IDE).

@jakubmisek, I hope this helps.

TypeError: A scalar of type 'double' used as an object in
C:\Users\Fibonacci\Desktop\PhpAppn04.09\phplib\src\MyWindow\MainWindow.php(51,12)
Stack trace:
#0 /_/src/Avalonia.Interactivity/EventRoute.cs(167,24): anonymous@function($content, $button, $e)
#1 /_/src/Avalonia.Interactivity/EventRoute.cs(101,20): EventRoute->RaiseEventImpl($e)
#2 /_/src/Avalonia.Interactivity/Interactive.cs(122,12): EventRoute->RaiseEvent($source, $e)
#3 C:\Users\Fibonacci\Desktop\PhpAppn04.09\Avalonia.Php\Controls\UxButton.cs(343,16): Interactive->RaiseEvent($e)
#4 C:\Users\Fibonacci\Desktop\PhpAppn04.09\Avalonia.Php\Controls\UxButton.cs(388,20): UxButton->OnClick()
#5 /_/Rx.NET/Source/src/System.Reactive/AnonymousObserver.cs(67,55): UxButton->OnPointerReleased($e)
#6 /_/Rx.NET/Source/src/System.Reactive/ObserverBase.cs(34,16): AnonymousObserver`1->OnNextCore($value)
#7 /_/Rx.NET/Source/src/System.Reactive/Subjects/Subject.cs(147,16): ObserverBase`1->OnNext($value)
#8 /_/src/Avalonia.Interactivity/RoutedEvent.cs(99,12): Subject`1->OnNext($value)
#9 /_/src/Avalonia.Interactivity/EventRoute.cs(148,24): RoutedEvent->InvokeRaised($sender, $e)
#10 /_/src/Avalonia.Interactivity/EventRoute.cs(101,20): EventRoute->RaiseEventImpl($e)
#11 /_/src/Avalonia.Interactivity/Interactive.cs(122,12): EventRoute->RaiseEvent($source, $e)
#12 /_/src/Avalonia.Input/MouseDevice.cs(313,16): Interactive->RaiseEvent($e)
#13 /_/src/Avalonia.Input/MouseDevice.cs(179,24): MouseDevice->MouseUp($device, $timestamp, $root, $p, $props, $inputModifiers)
#14 /_/src/Avalonia.Input/MouseDevice.cs(90,16): MouseDevice->ProcessRawEvent($e)
#15 /_/src/Avalonia.Input/InputManager.cs(35,12): MouseDevice->ProcessRawEvent($e)
#16 /_/src/Avalonia.Controls/TopLevel.cs(508,12): InputManager->ProcessInput($e)
#17 /_/src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs(520,16): TopLevel->HandleInput($e)
#18 /_/src/Windows/Avalonia.Win32/WindowImpl.WndProc.cs(30,16): WindowImpl->AppWndProc($hWnd, $msg, $wParam, $lParam)
#19 : WindowImpl->WndProc($hWnd, $msg, $wParam, $lParam)
#20 : UnmanagedMethods::DispatchMessage($lpmsg)
#21 /_/src/Windows/Avalonia.Win32/Win32Platform.cs(210,16): UnmanagedMethods::DispatchMessage($lpmsg)
#22 /_/src/Avalonia.Base/Threading/Dispatcher.cs(65,12): Win32Platform->RunLoop($cancellationToken)
#23 /_/src/Avalonia.Controls/ApplicationLifetimes/ClassicDesktopStyleApplicationLifetime.cs(120,12): Dispatcher->MainLoop($cancellationToken)
#24 /_/src/Avalonia.Controls/ApplicationLifetimes/ClassicDesktopStyleApplicationLifetime.cs(209,12): ClassicDesktopStyleApplicationLifetime->Start($args)
#25 C:\Users\Fibonacci\Desktop\PhpAppn04.09\AvaloniaApplication\Program.cs(12,50): ClassicDesktopStyleApplicationLifetimeExtensions::StartWithClassicDesktopLifetime($builder, $args, $shutdownMode)
#26 : Program::Main($args)
   at Pchp.Core.StrictConvert.AsObject(PhpValue value)
   at CallSite.Target(Closure , CallSite , Object , Context , CallerTypeParam , PhpValue )
   at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid4[T0,T1,T2,T3](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
   at <Root>src/MyWindow.MainWindow_php.anonymous@function(Closure <closure>, PhpValue content, PhpValue button, Object e) in C:\Users\Fibonacci\Desktop\PhpAppn04.09\phplib\src\MyWindow\MainWindow.php:line 51
   at anonymous@function#1(Closure , Context , PhpValue[] )
   at Pchp.Core.Reflection.RoutineInfo.Invoke(Context ctx, Object target, PhpValue[] arguments)
   at Pchp.Core.Reflection.RoutineInfo.Pchp.Core.IPhpCallable.Invoke(Context ctx, PhpValue[] arguments)
   at Closure.__invoke(PhpValue[] parameters)
   at Closure.Pchp.Core.IPhpCallable.Invoke(Context ctx, PhpValue[] arguments)
   at lambda_method2(Closure , Object , RoutedEventArgs )
   at Avalonia.Interactivity.Interactive.<AddHandler>g__InvokeAdapter|4_0[TEventArgs](Delegate baseHandler, Object sender, RoutedEventArgs args) in /_/src/Avalonia.Interactivity/Interactive.cs:line 62
   at Avalonia.Interactivity.Interactive.<>c__4`1.<AddHandler>b__4_1(Delegate baseHandler, Object sender, RoutedEventArgs args) in /_/src/Avalonia.Interactivity/Interactive.cs:line 68
   at Avalonia.Interactivity.EventRoute.RaiseEventImpl(RoutedEventArgs e) in /_/src/Avalonia.Interactivity/EventRoute.cs:line 167
   at Avalonia.Interactivity.EventRoute.RaiseEvent(IInteractive source, RoutedEventArgs e) in /_/src/Avalonia.Interactivity/EventRoute.cs:line 101
   at Avalonia.Interactivity.Interactive.RaiseEvent(RoutedEventArgs e) in /_/src/Avalonia.Interactivity/Interactive.cs:line 122
   at Avalonia.Php.Controls.UxButton.OnClick() in C:\Users\Fibonacci\Desktop\PhpAppn04.09\Avalonia.Php\Controls\UxButton.cs:line 343
   at Avalonia.Php.Controls.UxButton.OnPointerReleased(PointerReleasedEventArgs e) in C:\Users\Fibonacci\Desktop\PhpAppn04.09\Avalonia.Php\Controls\UxButton.cs:line 388
   at Avalonia.Input.InputElement.<>c.<.cctor>b__32_9(InputElement x, PointerReleasedEventArgs e) in /_/src/Avalonia.Input/InputElement.cs:line 223
   at Avalonia.Interactivity.RoutedEvent`1.<>c__DisplayClass2_0`1.<AddClassHandler>g__Adapter|0(Object sender, RoutedEventArgs e) in /_/src/Avalonia.Interactivity/RoutedEvent.cs:line 143
   at Avalonia.Interactivity.RoutedEvent.<>c__DisplayClass23_0.<AddClassHandler>b__0(ValueTuple`2 args) in /_/src/Avalonia.Interactivity/RoutedEvent.cs:line 92
   at System.Reactive.AnonymousObserver`1.OnNextCore(T value) in /_/Rx.NET/Source/src/System.Reactive/AnonymousObserver.cs:line 67
   at System.Reactive.ObserverBase`1.OnNext(T value) in /_/Rx.NET/Source/src/System.Reactive/ObserverBase.cs:line 34
   at System.Reactive.Subjects.Subject`1.OnNext(T value) in /_/Rx.NET/Source/src/System.Reactive/Subjects/Subject.cs:line 147
   at Avalonia.Interactivity.RoutedEvent.InvokeRaised(Object sender, RoutedEventArgs e) in /_/src/Avalonia.Interactivity/RoutedEvent.cs:line 99
   at Avalonia.Interactivity.EventRoute.RaiseEventImpl(RoutedEventArgs e) in /_/src/Avalonia.Interactivity/EventRoute.cs:line 148
   at Avalonia.Interactivity.EventRoute.RaiseEvent(IInteractive source, RoutedEventArgs e) in /_/src/Avalonia.Interactivity/EventRoute.cs:line 101
   at Avalonia.Interactivity.Interactive.RaiseEvent(RoutedEventArgs e) in /_/src/Avalonia.Interactivity/Interactive.cs:line 122
   at Avalonia.Input.MouseDevice.MouseUp(IMouseDevice device, UInt64 timestamp, IInputRoot root, Point p, PointerPointProperties props, KeyModifiers inputModifiers) in /_/src/Avalonia.Input/MouseDevice.cs:line 313
   at Avalonia.Input.MouseDevice.ProcessRawEvent(RawPointerEventArgs e) in /_/src/Avalonia.Input/MouseDevice.cs:line 179
   at Avalonia.Input.MouseDevice.ProcessRawEvent(RawInputEventArgs e) in /_/src/Avalonia.Input/MouseDevice.cs:line 90
   at Avalonia.Input.InputManager.ProcessInput(RawInputEventArgs e) in /_/src/Avalonia.Input/InputManager.cs:line 35
   at Avalonia.Controls.TopLevel.HandleInput(RawInputEventArgs e) in /_/src/Avalonia.Controls/TopLevel.cs:line 508
   at Avalonia.Win32.WindowImpl.AppWndProc(IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam) in /_/src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs:line 520
   at Avalonia.Win32.WindowImpl.WndProc(IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam) in /_/src/Windows/Avalonia.Win32/WindowImpl.WndProc.cs:line 30
   at Avalonia.Win32.Interop.UnmanagedMethods.DispatchMessage(MSG& lpmsg)
   at Avalonia.Win32.Win32Platform.RunLoop(CancellationToken cancellationToken) in /_/src/Windows/Avalonia.Win32/Win32Platform.cs:line 210
   at Avalonia.Threading.Dispatcher.MainLoop(CancellationToken cancellationToken) in /_/src/Avalonia.Base/Threading/Dispatcher.cs:line 65
   at Avalonia.Controls.ApplicationLifetimes.ClassicDesktopStyleApplicationLifetime.Start(String[] args) in /_/src/Avalonia.Controls/ApplicationLifetimes/ClassicDesktopStyleApplicationLifetime.cs:line 120
   at Avalonia.ClassicDesktopStyleApplicationLifetimeExtensions.StartWithClassicDesktopLifetime[T](T builder, String[] args, ShutdownMode shutdownMode) in /_/src/Avalonia.Controls/ApplicationLifetimes/ClassicDesktopStyleApplicationLifetime.cs:line 209
   at AvaloniaApplication.Program.Main(String[] args) in C:\Users\Fibonacci\Desktop\PhpAppn04.09\AvaloniaApplication\Program.cs:line 12

@jakubmisek
Copy link
Member

This is the MainWindow.php, line 51. right?

$button->Content = $content1;

In PHP, $content1 (double) can't be assigned to object. But I understand, that in .NET it is a common practice boxing any value to object. Currently, $content1 must be a PHP object to pass the assignment.

@FibonacciFox
Copy link
Author

@jakubmisek, thank you for your help.
I can't understand:
image

@jakubmisek
Copy link
Member

This behavior seems to be a bit inconsistent ... what should work now, is assigning only PHP object (class instance) to the $button->Content;

It's actually unexpected, that "works!" works.

We have to make it work in both cases.

@jakubmisek
Copy link
Member

thank you @FibonacciFox

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants