Comments (2)
Undefined property: stdClass::$name means that you have an undefined object. If I remember correctly, I think the reason why is because it is expecting a single agent string string instead of an array. I think you will have to loop through, and do $user = new WhichBrowser($agents); with each agent string.
To start to debug, walkthrough and var_dump everything. So do something like this: Try this:
$user = new WhichBrowser($agents);
var_dump($user);
// If it produces errors here, that probably means that $agents is not the data type that the WhichBrowser object is expecting.
$user = new WhichBrowser($agents);
var_dump($user);
$browser = $user->browser->name;
var_dump($browser);
Try that and see where you get the error.
From: AustenZeh [email protected]
Sent: Wednesday, July 15, 2015 3:12 PM
To: WhichBrowser/WhichBrowser
Subject: [WhichBrowser] Browser->Name Not working (#38)
Every time I write code like so:
$user = new WhichBrowser($agents);
$user->analyseUserAgent($agents['ua']);
$browser = $user->browser->name;
where agents is an array of Agent Strings, I get an error that reads:
Notice: Undefined property: stdClass::$name in.....
and I was hoping someone could help me out, because it does the same thing for when I try to get the version of the browser or the OS. Really the only thing that works is when I analyse the device so please help, thank you!
Reply to this email directly or view it on GitHubhttps://github.com//issues/38.
from parser-php.
Using WhichBrowser from PHP isn't officially supported yet, but if you do want to use it, you need pass an options array with the headers to the WhichBrowser object. Also keep in mind that name is not always defined. Only when WhichBrowser knows the name it will set this property.
$options = array('headers' => getallheaders());
$user = new WhichBrowser($options);
if (isset($user->browser->name)) {
echo $user->browser->name;
} else {
echo "Browser name is not known";
}
If you just have a user agent string you want to analyse you need to do it like this:
$options = array('headers' => array('User-Agent' => 'Mozilla/5.0........'));
$user = new WhichBrowser($options);
if (isset($user->browser->name)) {
echo $user->browser->name;
} else {
echo "Browser name is not known";
}
from parser-php.
Related Issues (20)
- Proposal: Set all names to English non-extended Latin character set range to allow automatic translation templates
- Incorrect detection of user agent string
- Invalid
- Undefined property HOT 1
- Brave Browser - Incorrect detection of user agent string HOT 2
- Incompatible with PSR/Cache ^2 HOT 3
- Updating notes for `webOs` browser
- Get brand information HOT 1
- Undetected user agents HOT 1
- Projects with low Build Activity - Survey
- [PHP 8.1] Deprecated functions HOT 3
- Chrome wrong version Detection HOT 3
- Wrong autoload HOT 1
- PHP 8.2 deprecations HOT 10
- Incompatability with automattic/jetpack-autoloader HOT 2
- macOS not detected HOT 3
- $os property non-nullable
- Project abandoned? HOT 3
- SSL certificate expired HOT 1
- Incorrect definition: Chuwi HiPad Max as Apple
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from parser-php.