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

Type Hints error: ->addVisitThatExpiresAt( Carbon::now()->addHours(2) ); #10

Closed
selfpaidinc opened this issue Jul 14, 2017 · 12 comments
Closed

Comments

@selfpaidinc
Copy link

When trying to use addVisitThatExpiresAt I get an exception error.

Argument 1 passed to Cyrildewit\PageVisitsCounter\Classes\SessionHistory::fromCamelCaseToDashes() must be an instance of Cyrildewit\PageVisitsCounter\Classes\string, string given
@cyrildewit
Copy link
Owner

cyrildewit commented Jul 14, 2017

Hi selfpaidinc,

First I want to thank you for reporting this issue.

I did a little research and found out why you are getting this error. I was type hinting a parameter of the function fromCamelCaseToDashes: (string $value). But I didn't knew that type hints cannot be used with types such as int or string.

Source: https://stackoverflow.com/questions/5724677/php-type-hinting-to-primitive-values

I will fix it and release a new version.

It would be great if you could post a comment when the new version fixed it for you, so I can close this issue.

@selfpaidinc
Copy link
Author

Thanks very much for the quick reply I will be sure to comment when it's fixed. Also, any plans on allowing to order model items by view count?

@cyrildewit
Copy link
Owner

cyrildewit commented Jul 14, 2017

I released v0.1.5. So a composer update will install the new version.

Could you create another "issue" where you describe this missing feature. Because it has nothing to do with this "issue".

@cyrildewit cyrildewit changed the title ->addVisitThatExpiresAt( Carbon::now()->addHours(2) ); Type Hints error: ->addVisitThatExpiresAt( Carbon::now()->addHours(2) ); Jul 14, 2017
@selfpaidinc
Copy link
Author

Ran update, issue resolved! Thanks for the super fast response.

@selfpaidinc
Copy link
Author

Sorry, must not have looked into this completely. Below my page content there is another exception.

(1/1) InvalidArgumentExceptionUnknown setter 'date'

in Carbon.php (line 758)
at Carbon->__set('date', '2017-07-14 16:57:26.000000')
at DateTime->__sleep()
at serialize(array('_token' => 'ftaE4vKPtBORLyXhFH5HGmGJS6qtifjuXRjgBcBI', '_previous' => array('url' => 'http://www.**********.com/*****/****************'), '_flash' => array('old' => array(), 'new' => array()), 'page-visits-counter' =>array('history' => array('track' => array(array('visitable_id' => 3, 'expires_at' => object(Carbon)))))))in Store.php (line 129)
at Store->save()in StartSession.php (line 88)
at StartSession->terminate(object(Request), object(Response))in Kernel.php (line 218)
at Kernel->terminateMiddleware(object(Request), object(Response))in Kernel.php (line 189)
at Kernel->terminate(object(Request), object(Response))in index.php (line 58)

@selfpaidinc selfpaidinc reopened this Jul 14, 2017
@cyrildewit
Copy link
Owner

cyrildewit commented Jul 14, 2017

Could you tell me which Laravel version you are using? and on which version of PHP you are running the application. It might be possible that it is not compatible.

It seems that other people who are using HHVM, that they are getting this error too even when they are not using this package.

@selfpaidinc
Copy link
Author

I'm using Laravel 5.4 and HHVM

@cyrildewit
Copy link
Owner

cyrildewit commented Jul 14, 2017

Are you caching the model where you are calling the ->addVisitThatExpiresAt() function on?

facebook/hhvm#5893 (comment)

@selfpaidinc
Copy link
Author

I'm still developing so not caching anything yet.

@cyrildewit
Copy link
Owner

I don't think this has anything to do with Laravel Page Visits Counter. Can you maybe post a screenshot of the full error on the webpage and (if it's there) the error inside the laravel.log file that you can find inside the storage directory.

@selfpaidinc
Copy link
Author

When I comment out $track->addVisitThatExpiresAt(Carbon::now()->addHours(3)); the error goes away.

image

[2017-07-14 16:09:28] local.ERROR: exception 'InvalidArgumentException' with message 'Unknown setter 'date'' in /var/www/clients/client1/web1/web/laravel/vendor/nesbot/carbon/src/Carbon/Carbon.php:758
Stack trace:
#0 (): Carbon\Carbon->__set()
#1 (): DateTime->__sleep()
#2 /var/www/clients/client1/web1/web/laravel/vendor/laravel/framework/src/Illuminate/Session/Store.php(129): serialize()
#3 /var/www/clients/client1/web1/web/laravel/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(88): Illuminate\Session\Store->save()
#4 /var/www/clients/client1/web1/web/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(218): Illuminate\Session\Middleware\StartSession->terminate()
#5 /var/www/clients/client1/web1/web/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(189): Illuminate\Foundation\Http\Kernel->terminateMiddleware()
#6 /var/www/clients/client1/web1/web/laravel/public/index.php(58): Illuminate\Foundation\Http\Kernel->terminate()
#7 {main}  

@cyrildewit
Copy link
Owner

I'm sorry but I can't fix this. It has something to do with HHVM. I think when you upload your application to a real web server (like a droplet of DigitalOcean) it will work.

It seems that HHVM compiles php code differently than Apache or nginx.

Try it again by running the application with php artisan serve. This will use the original php.

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

No branches or pull requests

2 participants